I was trying to configure spring 3.1 and hibernate. I have written a simple test project. where I have user domain and userDao and its implementation
let me show yo
There are no transactions in your sample project. Add:
<tx:annotation-driven />
And annotate your DAO with @Transactional
:
@Transactional
@Repository
public class UserDaoImpl implements UserDao
Two notes:
you are correctly marking your DAO with @Repository, but it only handles exception translation:
A class thus annotated is eligible for Spring DataAccessException translation
consider placing @Transactional
on higher level classes (@Service
s), see What is the right way to use spring MVC with Hibernate in DAO, sevice layer architecture for discussion
update to the latest jar. Their was jira created.
https://jira.springsource.org/browse/SPR-8776
You must set the propagation "REQUIRED" like this:
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
I do not know whether this is a spring bug.