I am having issues when a method calls a method with the @Transactional. When I do, it appears to be ignored.
The scenario I have is that I have a base repository class that provides a bunch of convenience methods and they have the @Transactional. If the caller doesn't have @Transactional, it is ignored.
Example:
We use the <tx:annotation-driven/> configuration and inject the FooBarRepository. This will generate the folowing exception:Code:@Repository public abstract class AbstractRepository { @Transactional public Object doSomethingCommon(Long pk) throws DataAccessException { ...some hibernate code } } public FooBarRepository extends AbstractRepository { public Object doSomethingCommonOnFooBar() { doSomethingCommon(foobarId); } }
Should this work? If I also add the @Transactional to doSomethingOnFooBar(), it works. I would really like to get this to cascade so business logic can call into code without having to always know that somewhere in the code stack there is an @Transactional.Code:org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544) ....
So, is there a way to get the <tx:annotation-driven/> to proxy more then the top level methods? If so, how do we do it? Is this a bug?
Hope this is clear.


Reply With Quote
The problem is that if you call a method on yourself (as you are doing), it completely bypasses the proxy. This is a restriction with any decorator/proxy based frameworks (EJB, Spring etc.)
