Spring + JPA @Transactional does not commit

I understand that a similar question was asked before, but I could not find a solution to my problem. Basically, I'm trying to use JPA through Hibernate in Spring, but for some reason the data is not being saved. Disabling debugging during a spring transaction does not detect anything - the EntityManager is open and closed, but nothing is visible, as far as the transaction manager is concerned ... I'm sure I miss something big, any help is appreciated! See below for more details.

TIA

Oliver

The basic layout is as follows: class FooDaoJPA s save function calls entityManager.persist(object) to save the object.

class FooServiceImpl implements the service interface:

 @Transactional(rollbackFor = DataAccessException.class, readOnly = false, timeout = 30, propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT) public void saveFoo(Foo foo) throws DataAccessException { fooDao.save(foo); } 

It is noted that fooDao is introduced by spring IoC

Finally, the controller is introduced by a FooService and calls saveFoo() to save the data.

JPA configuration

 <!-- JPA Entity Manager Factory --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:dataSource-ref="feDataSource"/> <!-- Transaction Config --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" p:entityManagerFactory-ref="entityManagerFactory"/> <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/> 
+6
spring
source share
3 answers

Pay attention to mode="aspectj" in your configuration. It requires additional configuration, and usually you should not use it if you do not understand what this means and why you need it. See 10.5.6 Using @Transactional .

+1
source share

The first thing that seems like a potential problem is your distribution settings. Here is the documentation showing the values ​​you can specify:

http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/transaction/annotation/Propagation.html

Please note that you have indicated SUPPORTS that "support the current transaction, execute the transaction without transactions if it does not exist." You will probably need REQUIRED, which is the default, and will either use an existing transaction or create one if it does not exist.

+1
source share

In my case:

Using JPA with Spring MVC - all my tests and code went fine without errors - the symptom was that the commits simply would not be stored in 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 a fix in my case. Without annotation, Spring will not scan @Transactional annotation

0
source share

All Articles