Results 1 to 4 of 4

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.

    Everything is very standard. I am going by the book here and not doing anything unusual.

    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 (this is by the book):

    <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="transactionManager"
    class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

    <bean id="transactionAttributeSource"
    class="org.springframework.transaction.interceptor .MatchAlwaysTransactionAttributeSource">
    </bean>

    <bean id="faqDao" class="FAQDaoImpl">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean>

    <bean id="faqServiceTarget" class="FAQServiceImpl">
    <constructor-arg>
    <ref bean="faqDao"/>
    </constructor-arg>
    </bean>

    <bean id="faqService"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="proxyInterfaces">
    <list>
    <value>FAQService</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>

    The Dao code:
    public void save(A a, B a) {
    getHibernateTemplate().saveOrUpdate(a);
    getHibernateTemplate().saveOrUpdate(b);
    }

    For test purposes, A and B are very simple classes with just an id and a name and straightforward mapping.


    Everything works fine when I remove Spring from the equation, but when I take my Hibernate app and turn it into a Spring app, somehow Hibernate is not turning auto-commit off. What could Spring be doing to the session/connection that could alter Hibernate's behavior ?

    Any ideas, or, recommendations on how to debug this ?

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Last edited by robyn; May 14th, 2006 at 10:48 AM.

  3. #3
    Join Date
    Aug 2007
    Posts
    5

    Default Same Problem

    Hello, I am using the same technologies and I am having the same problem, can anyone help me please?

    Thank you.

    PD: The link indicating the solution is wrong, it redirects me to the same forum page.

  4. #4
    Join Date
    Aug 2007
    Posts
    5

Similar Threads

  1. Replies: 3
    Last Post: Mar 1st, 2010, 05:45 PM
  2. Replies: 2
    Last Post: Jul 15th, 2005, 05:19 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
  •