-
Oct 4th, 2007, 07:11 AM
#1
Spring+Jotm+Hibernate - connection always in autocommit
Current version of my app works with HibernateTransactionManager w/o JTA or XA stuff on Resin 2.1.
I am targeting JTA XA to address common issues - mixing jms and db access, mixing db and cache. Since I am out of full j2ee AS I decided to go for JOTM.
Spring config looks trivial, but it seems like I am missing some very major, not to say blatant stuff I can't track down.
I have very simple test, hibernateTemplate.save, explicit transactions using PlatformTransactionManager.getTransaction. all the way like I used to do using no-JTA. Now, the problem is that it seems my connection always stays in autocommit mode !
I am using MySql 5.0 and the new connector w/ XA support, plus XA datasource - bean in Spring context, no JNDI.
Here is the config for Spring:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean" singleton="true">
<property name="mappingResources">
<list>
<value>...alert.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
...
<prop key="hibernate.transaction.factory_class">org.hibe rnate.transaction.JTATransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">o rg.hibernate.transaction.JOTMTransactionManagerLoo kup</prop>
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.connection.release_mode">after_stat ement</prop>
</props>
</property>
<property name="jtaTransactionManager">
<ref bean="jotm"/>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean id="jotm" class="org.springframework.transaction.jta.JotmFac toryBean"/>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
<property name="userTransaction" ref="jotm"/>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate.Hibernate Template" singleton="false">
<property name="sessionFactory"><ref bean="sessionFactory"/></property>
<property name="jdbcExceptionTranslator"><ref bean="jdbcExceptionTranslator"/></property>
</bean>
Here are the logs - tx.begin and rollback (no rollback happens) .
What looks kind of weird is that
JtaTransactionManager:751 - Initiating transaction rollback
happens after JDBC connection is released.
14:05:56,218 [main] DEBUG JtaTransactionManager:319 - Using transaction object [org.springframework.transaction.jta.JtaTransaction Object@29a046]
14:05:56,218 [main] DEBUG JtaTransactionManager:347 - Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
14:05:56,218 [main] DEBUG TransactionSynchronizationManager:222 - Initializing transaction synchronization
14:05:56,218 [main] DEBUG SessionFactoryUtils:316 - Opening Hibernate Session
14:05:56,234 [main] DEBUG JDBCContext:155 - successfully registered Synchronization
14:05:56,234 [main] DEBUG SessionFactoryUtils:324 - Registering Spring transaction synchronization for new Hibernate Session
14:05:56,234 [main] DEBUG TransactionSynchronizationManager:168 - Bound value [org.springframework.orm.hibernate3.SessionHolder@7 81046] for key [org.hibernate.impl.SessionFactoryImpl@746d23] to thread [main]
14:05:56,234 [main] DEBUG TransactionSynchronizationManager:140 - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@7 81046] for key [org.hibernate.impl.SessionFactoryImpl@746d23] bound to thread [main]
14:05:56,234 [main] DEBUG HibernateTemplate:364 - Found thread-bound Session for HibernateTemplate
14:05:56,250 [main] DEBUG AbstractBatcher:311 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
14:05:56,250 [main] DEBUG ConnectionManager:415 - opening JDBC connection
14:05:56,250 [main] DEBUG AbstractBatcher:424 - preparing statement
14:05:56,390 [main] DEBUG AbstractBatcher:319 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
14:05:56,390 [main] DEBUG AbstractBatcher:470 - closing statement
14:05:56,390 [main] DEBUG HibernateTemplate:388 - Not closing pre-bound Hibernate Session after HibernateTemplate
14:05:56,390 [main] DEBUG JtaTransactionManager:846 - Triggering beforeCompletion synchronization
14:05:56,390 [main] DEBUG TransactionSynchronizationManager:193 - Removed value [org.springframework.orm.hibernate3.SessionHolder@7 81046] for key [org.hibernate.impl.SessionFactoryImpl@746d23] from thread [main]
14:05:56,390 [main] DEBUG SessionFactoryUtils:772 - Closing Hibernate Session
14:05:56,390 [main] DEBUG ConnectionManager:374 - performing cleanup
14:05:56,390 [main] DEBUG ConnectionManager:435 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
14:05:56,390 [main] DEBUG JtaTransactionManager:751 - Initiating transaction rollback
14:05:56,390 [main] DEBUG JDBCContext:199 - after transaction completion
14:05:56,390 [main] DEBUG ConnectionManager:398 - aggressively releasing JDBC connection
14:05:56,390 [main] DEBUG JtaTransactionManager:875 - Triggering afterCompletion synchronization
14:05:56,390 [main] DEBUG TransactionSynchronizationManager:276 - Clearing transaction synchronization
would appreciate any clue. im pretty sure it's kinda obvious thing i'm overlooking.
thx.
-
Oct 26th, 2007, 10:34 AM
#2
My experience with JOTM is that it is quite buggy.
Maybe you should consider using the Embedded JBoss or better
yet using a real application server.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules