I changed my TransactionMangager to use JTA/JOTM which is supported by Spring
Code:
<property name="hibernateProperties">
<props>
<prop key="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.JOTMTransactionManagerLookup</prop>
<prop key="jta.UserTransaction">java:comp/UserTransaction</prop>
</props>
</property>
Code:
INFO com.acme.service.NewFileEventHandlerTestMocked - test() START...
INFO com.acme.service.NewFileEventHandlerTestMocked - userTransaction.begin()
Transaction JTA began...
Code:
DEBUG org.springframework.transaction.interceptor.TransactionInterceptor - Getting transaction for method 'createAcmeObject' in class [com.acme.manager.AcmeObjectManager]
DEBUG org.springframework.transaction.jta.JtaTransactionManager - Using transaction object [org.objectweb.jotm.Current@19e733e]
DEBUG org.springframework.transaction.jta.JtaTransactionManager - Participating in existing transaction
DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Initializing transaction synchronization
My JOTM transaction is used...cool!
Code:
INFO com.acme.dao.AcmeObjectDao - begin dao.create(name,date)
DEBUG org.springframework.orm.hibernate.SessionFactoryUtils - Opening Hibernate session
DEBUG net.sf.hibernate.impl.SessionImpl - opened session
DEBUG org.springframework.orm.hibernate.SessionFactoryUtils - Registering Spring transaction synchronization for Hibernate session
DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Bound value [org.springframework.orm.hibernate.SessionHolder@1b5eba4] for key [net.sf.hibernate.impl.SessionFactoryImpl@1b00766] to thread [main]
DEBUG net.sf.hibernate.impl.SessionImpl - generated identifier: 349501
DEBUG net.sf.hibernate.impl.SessionImpl - saving [com.acme.domain.AcmeObject#349501]
INFO com.acme.dao.AcmeObjectDao - end dao.create()
why does Spring still invoke a commit at the end of my dao method ???
Code:
DEBUG org.springframework.transaction.interceptor.TransactionInterceptor - Invoking commit for transaction on method 'createAcmeObject' in class [com.acme.manager.AcmeObjectManager]
DEBUG org.objectweb.jotm.jta - status=STATUS_ACTIVE
DEBUG org.springframework.transaction.jta.JtaTransactionManager - Triggering beforeCommit synchronization
DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
DEBUG net.sf.hibernate.impl.SessionImpl - executing flush
DEBUG net.sf.hibernate.SQL - insert into ACME_TABLE ...
DEBUG org.springframework.transaction.jta.JtaTransactionManager - Triggering beforeCompletion synchronization
DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Removed value [org.springframework.orm.hibernate.SessionHolder@1b5eba4] for key [net.sf.hibernate.impl.SessionFactoryImpl@1b00766] from thread [main]
DEBUG org.springframework.orm.hibernate.SessionFactoryUtils - Closing Hibernate session
2004-09-15 12:19:08,156 DEBUG org.springframework.orm.hibernate.SessionFactoryUtils - Closing Hibernate session
2004-09-15 12:19:08,156 DEBUG net.sf.hibernate.impl.SessionImpl - closing session
2004-09-15 12:19:08,156 DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
2004-09-15 12:19:08,156 DEBUG org.springframework.transaction.jta.JtaTransactionManager - Triggering afterCompletion synchronization
2004-09-15 12:19:08,156 DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Clearing transaction synchronization
INFO org.objectweb.jotm - set rollback only
DEBUG org.objectweb.jotm.jta - status=STATUS_MARKED_ROLLBACK
DEBUG org.objectweb.jotm.jta - Commit local transaction -> rolled back!
And my JTA transaction is rolled back ??
My test case is bellow
Code:
transactionJTA.begin();
AcmeObject newAcme=service.createAcmeObject(...); //2 DAO calls in this method
newAcme.setName("name");
transactionJTA.commit();
I'm sure i made a mistake but if anyone can help me....