Announcement Announcement Module
No announcement yet.
Spring+Jotm+Hibernate - connection always in autocommit Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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,, 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">

    <property name="hibernateProperties">
    <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>

    <property name="jtaTransactionManager">
    <ref bean="jotm"/>

    <property name="dataSource">
    <ref bean="dataSource"/>

    <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 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>

    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 [email protected]]
    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 [[email protected] 81046] for key [[email protected]] to thread [main]
    14:05:56,234 [main] DEBUG TransactionSynchronizationManager:140 - Retrieved value [[email protected] 81046] for key [[email protected]] 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 [[email protected] 81046] for key [[email protected]] 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.


  • #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.