I need to have two transaction managers in my Spring application. I use them by annotating service classes by @Transactional("nameOfTxManager"). Howewer, I am only able to use one of them - when I call some method of service class annotated with second transaction manager, I get "org.hibernate.HibernateException: No Session found for current thread" exception. Here is some code that reflects problem:
1st service class:
2nd service classCode:@Transactional("txManagerHSQL") public class LocalSynchroServiceImpl extends SynchroServiceImpl implements LocalSynchroService { public List<Synchro> findAll() { return getDaoAgent().getSynchroDao().findAllLocal(); } }
Piece of configuration connected with transactions:Code:@Transactional("txManagerMySQL") public class RemoteSynchroServiceImpl extends SynchroServiceImpl implements RemoteSynchroService { public List<Synchro> findAll() { return getDaoAgent().getSynchroDao().findAllRemote(); } }
Exception:Code:<tx:annotation-driven /> <bean id="txManagerHSQL" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactoryHSQL"/> </bean> <bean id="txManagerMySQL" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactoryMySQL"/> </bean>
The annotation of 2nd service class is interpreted correctly, because when I change name of transaction manager to some random name, I get the exception that such bean was not found. And also, when I set name as @Transactional("txManagerHSQL"), it works fine but with not the transaction manager I want.Code:org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:941) at pl.mbrnwsk.clientsRegister.dao.DaoImpl.getCurrentSession(DaoImpl.java:75)


Reply With Quote
