Hibernate JPA and Spring javax.persistence.TransactionRequiredException: no transaction is in progress

Viewed 60765

When I call:

entityManager.flush()

I get the exception mentioned in the title.

I am using Hibernate JPA.

13 Answers

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"/>

Please make sure that your handler method is declared as public

@Transactional 
@RequestMapping('/test')
public String doTest() {
    // do your stuff here 
    return 'testview';
}

Make sure that your spring configuration includes the following line:

<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager" />

mode can be either proxy or aspectj and transaction-manager has to point to your transaction manager been.

Related