I am new to the jpa and spring world and I am currently doing some unit test on a simple method but keep getting this error message only when I run my test class in unit tes
I got a similar problem when I try the unit tests with IntelliJ, even though its working using cli
of maven-surefire-plugin
it turns out that IntelliJ build was using javac compiler and even though it specified in pox.xml to use ajc compiler there is a reported bug for IntelliJ at IDEA-135483
that made @Transactional
not working
and give you No transactional EntityManager available
if that is your case, you need to change java compiler to use ajc
instead of javac
and post-compile weave mode
in project structure
I think EntityManager is null.Try Like this,may be it work
private EntityManager entityManager = null;
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
By declaring
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class })
you have completely (albeit unintentionally) disabled support for test-managed transactions. The reason is that you have omitted TransactionalTestExecutionListener
from the list of declared listeners.
Note, however, that TransactionalTestExecutionListener
is declared transparently by default. Thus, when you delete your @TestExecutionListeners
declaration from your test class, TransactionalTestExecutionListener
is once again enabled.
You can of course find details in the Spring Reference Manual here.
Regards,
Sam (author of the Spring TestContext Framework ;) )