Results 1 to 3 of 3

Thread: Spring Hibernate transaction rollback not working right

  1. #1
    Join Date
    Jun 2005
    Posts
    22

    Default Spring Hibernate transaction rollback not working right

    Spring 1.2.2
    Hibernate 3.0.5
    SQL Server 7, jTDS 1.0.3
    JBoss 4.0.2

    I have an app using Spring's declarative transactions, delegating to HibernateTransactionManager, which is configured to use the JTATransactionManager strategy. I have an update that affects two tables, and if there is an exception on the second update, the first update does not get rolled back. I can see that the problem is that although everything is done within a single JTA transaction and the JTA transaction is rolled back, the individual updates are done with auto-commit ON.

    Interestingly, I created a small test webapp that does not use Spring, but uses explicit Hibernate transaction management, and uses the exact same Hibernate configuration and the same JBoss datasource configuration, and things work fine. Hibernate is clearly setting auto-commit to false, and then setting it back to true after the transaction is done. Rollback correctly rolls back the first update.

    Here is my Spring configuation:

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName"><value>java:MSSQLDS</value></property>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource"/>
    </property>
    <property name="mappingResources">
    <list>
    <value>A.hbm.xml</value>
    <value>B.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.SQLS erverDialect</prop>
    <prop key="hibernate.transaction.factory_class">org.hibe rnate.transaction.JTATransactionFactory</prop>
    <prop key="hibernate.connection.release_mode">on_close</prop>
    </props>
    </property>
    </bean>

    <bean id="aDao" class="ADaoImpl">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

    <bean id="aServiceTarget" class="AServiceImpl">
    <constructor-arg>
    <ref bean="aDao"/>
    </constructor-arg>
    </bean>

    <bean id="aService"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="proxyInterfaces">
    <list>
    <value>AService</value>
    </list>
    </property>
    <property name="target">
    <ref bean="faqServiceTarget"/>
    </property>
    <property name="transactionManager">
    <ref bean="transactionManager"/>
    </property>
    <property name="transactionAttributeSource">
    <ref bean="transactionAttributeSource"/>
    </property>
    </bean>

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    If you want JTA transactions, you should use Spring's JtaTransactionManager instead of HibernateTransactionManager.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Jun 2005
    Posts
    22

    Default

    It looks like that solved my problems and everything is working great.

    Thank you.

Similar Threads

  1. Replies: 3
    Last Post: Mar 1st, 2010, 05:45 PM
  2. Replies: 3
    Last Post: Aug 16th, 2007, 12:10 PM
  3. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •