Spring @Transactional not creating required transaction Spring @Transactional not creating required transaction spring spring

Spring @Transactional not creating required transaction


The instance of entity manager obtained from EntityManagerFactory.createEntityManager() doesn't participate in Spring-managed transactions.

The usual way to obtain an entity manager is to inject it using @PersistenceContext-annotated property:

@PersistenceContextpublic void setEntityManager(EntityManager em) { ... }


The problem is likely caused by a combination of you annotating a protected method, and using proxy-target-class="true". That's a bad mix. The transactional proxy generated by Spring will only work properly with public annotated methods, but it won't complain if they're not.

Try either making the saveOrUpdate() method public or, better yet, define an interface for your DAO, and remove the proxy-target-class="true" setting. This is the safest, most predictable technique.


In my case:

Using JPA with Spring MVC - all of my tests and code ran fine without error - symptom was that commits would simply not save to the database no matter what I tried.

I had to add to my applicationContext.xml and cglib-nodep-2.1_3.jar aopalliance-1.0.jar

Definitely the fix in my case. Without annotation-driven Spring will not scan for the @Transactional annotation