KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In the following piece of code (Spring 3): @Transactional("txManager") public class DaoHolder { @Transactional(value="txManager", readOnly=false, propagation=Propagation.REQUIRES_NEW, rollbackFor={Exception.class}) private void runTransactionalMethod() throws Exception { dao1.insertRow(); dao2.insertRow(); //throw new Exception(); } //... } dao1 uses a session factory attached to datasource1 dao2 uses a session factory attached to datasource2 txManager is a HibernateTransactionManager using the same session factory as dao1 The code above works correctly in a transactional manner - in particular, when no exception is thrown, each dao operation gets committed (to 2 different datasources). When an exception is thrown each dao operation gets rolled back. My question is: why does it work? Everywhere I've read I've been told to use a JtaTransactionManager when handling multiple datasources. I'd prefer not to use JTA. What might be the consequences if I leave it running under a HibernateTransactionManager? Some more details for the interested: Each datasource is defined like so: <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="initialSize" value="${jdbc.initial_size}" /> <property name="maxActive" value="${jdbc.max_active}" /> </bean> Each session factory is defined like so: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <p
Tags (comma-separated)
Save Edits
Cancel