When I call:
entityManager.flush()
I get the exception mentioned in the title.
I am using Hibernate JPA.
After encountering this problem myself and spending a few hours trying to get it resolved I finally found a reason for it: Spring has a bug and can't maintain transactions with @Transactional
annotation if the same class has @Service
annotation for the means of autowiring.
Once the @Service
annotation was removed from the service class in question, and an appropriate bean was declared in the XML config:
<bean id="myService" class="com.example.myapp.service.MyServiceImpl" />
the problem is gone.
Check this JIRA bug for more details.
Ensure that you have an active transaction when this statement executes. If you are using JPA use EntityManager.getTransaction().begin(). This is assuming that you are using JPA outside a JTA transaction scope.
If you are running the application inside a container with JTA support you can also use JTA UserTransaction to manage transactions.
My Problem was to do with the way that I setup the <tx:annotation-driven/>
Element in my context definition -
Originally I had load time weaving enabled (not knownley) that read <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
and by simply removing the 2nd attribute - everything worked (took 2 hours of head banging though). I believe the 2nd element relates to the @Configurable sterotype but can let other (smarter) people explain the difference & why one would work & the other does does not.. Hope this helps...
working definition= <tx:annotation-driven transaction-manager="transactionManager"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With