Announcement Announcement Module
Collapse
No announcement yet.
Spring and Hibernate integration: Transaction not successfully started Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring and Hibernate integration: Transaction not successfully started

    Hi all,

    I configure Spring and Hibernate integration to use SessionFactory via Spring. I have an application context as following:
    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="hibernateProperties">
    <value>
    hibernate.dialect=org.hibernate.dialect.SQLServerD ialect
    hibernate.query.substitutions=true 'Y', false 'N'
    </value>
    </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    and I have implemented Java code as following:
    org.hibernate.Session hbmSession = getSessionFactory().getCurrentSession().getSession ();
    org.hibernate.Transaction transaction = null;
    transaction = hbmSession.beginTransaction();
    org.hibernate.SQLQuery query = hbmSession.createSQLQuery(script);
    int rowCount = query.executeUpdate();
    transaction.commit();
    when run this code I have error as following:
    org.springframework.transaction.TransactionSystemE xception: Could not roll back Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
    at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doRollback(HibernateTransactionManage r.java:580)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.processRollback(AbstractP latformTransactionManager.java:753)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.rollback(AbstractPlatform TransactionManager.java:730)
    at org.springframework.test.AbstractTransactionalSpri ngContextTests.endTransaction(AbstractTransactiona lSpringContextTests.java:359)
    at org.springframework.test.AbstractTransactionalSpri ngContextTests.onTearDown(AbstractTransactionalSpr ingContextTests.java:287)
    at org.springframework.test.AbstractSingleSpringConte xtTests.tearDown(AbstractSingleSpringContextTests. java:144)
    at junit.framework.TestCase.runBare(TestCase.java:130 )
    at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:76)
    at junit.framework.TestResult$1.protect(TestResult.ja va:106)
    at junit.framework.TestResult.runProtected(TestResult .java:124)
    at junit.framework.TestResult.run(TestResult.java:109 )
    at junit.framework.TestCase.run(TestCase.java:118)
    at junit.framework.TestSuite.runTest(TestSuite.java:2 08)
    at junit.framework.TestSuite.run(TestSuite.java:203)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.maven.surefire.junit.JUnitTestSet.execu te(JUnitTestSet.java:213)
    at org.apache.maven.surefire.suite.AbstractDirectoryT estSuite.executeTestSet(AbstractDirectoryTestSuite .java:140)
    at org.apache.maven.surefire.suite.AbstractDirectoryT estSuite.execute(AbstractDirectoryTestSuite.java:1 27)
    at org.apache.maven.surefire.Surefire.run(Surefire.ja va:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.maven.surefire.booter.SurefireBooter.ru nSuitesInProcess(SurefireBooter.java:345)
    at org.apache.maven.surefire.booter.SurefireBooter.ma in(SurefireBooter.java:1009)
    Caused by: org.hibernate.TransactionException: Transaction not successfully started
    at org.hibernate.transaction.JDBCTransaction.rollback (JDBCTransaction.java:149)
    at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doRollback(HibernateTransactionManage r.java:577)
    ... 27 more
    Caused by: org.hibernate.TransactionException: Transaction not successfully started
    at org.hibernate.transaction.JDBCTransaction.rollback (JDBCTransaction.java:149)
    at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doRollback(HibernateTransactionManage r.java:577)
    ... 27 more
    Could anyone tell me why this error occured and show me how to fix it?

    I really appreciate it.

    Ringo

  • #2
    I am not a Spring user; I stumbled on this thread while searching the web for a similar issue. We do use Hibernate on our project.

    That TransactionException seems to be thrown when rollback() is called after the commit(), when there are no changes to roll back. In your case, it looks from the stack trace like AbstractSingleSpringContextTests.tearDown is trying to roll back the transaction after your test case commits it.

    HTH

    Comment

    Working...
    X