I understand the similar question have been asked before here, but I couldn’t find the solution to my problem. Basically, I am trying to use JPA through Hibernate in Spring, but the data is not being persisted for some reason.Turning on debug on spring transaction reveals nothing – EntityManager open and closed, but nothing shows up as far as transaction manager concerns … I am sure I miss something big, any help is appreciated! see the following for more details.
TIA
Oliver
The basic layout is as follows: class FooDaoJPA’s save function calls out entityManager.persist(object) to persist the object.
class FooServiceImpl implements the service interface by:
@Transactional(rollbackFor = DataAccessException.class,
readOnly = false, timeout = 30,
propagation = Propagation.SUPPORTS,
isolation = Isolation.DEFAULT)
public void saveFoo(Foo foo) throws DataAccessException {
fooDao.save(foo);
}
Noted that fooDao is injected by Spring IoC
Finally controller is injected a FooService and call saveFoo() to persist 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"/>
Note the
mode="aspectj"in your configuration. It requires additional configuration and usually you shouldn’t use it unless you understand what does it mean and why do you need it. See 10.5.6 Using @Transactional.