These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Explicit transaction rollback
PostPosted: Fri Aug 26, 2005 9:51 am 
Newbie

Joined: Mon Aug 15, 2005 11:25 am
Posts: 10
Hibernate version: 3.1 Beta

Name and version of the database you are using: MySQL

Hi all,

I want to implement a method that roolback a hibernate transaction when I want...

What can I do to do this?
I try to use the session.getTransaction().rollback() method. But it does not work.

Code:
public class HibernateDataAccessObject extends HibernateDaoSupport implements IDataAccessObject {

    public void rollback() {

        // (1)
        this.getSession(true).getTransaction().rollback();

        // (2)
        this.getHibernateTemplate().getSessionFactory().getCurrentSession().getTransaction().rollback();
   }


The (1) do this :
org.springframework.transaction.TransactionSystemException: Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
org.hibernate.TransactionException: Transaction not successfully started

and the (2), this :
org.hibernate.HibernateException: No TransactionManagerLookup specified

I don't know what can I do...

Thank you...


Top
 Profile  
 
 Post subject: Re: Explicit transaction rollback
PostPosted: Fri Aug 26, 2005 10:31 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
From the exception you're getting "org.hibernate.TransactionException: Transaction not successfully started " it appears that you aren't working within a Transaction so there is nothing to rollback.

You have to execute Transaction tx = session.beginTransaction() and then execute tx.rollback(); on that transaction.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 2:52 am 
Newbie

Joined: Mon Aug 15, 2005 11:25 am
Posts: 10
Hi,
Thank you for your help.

I am working with the spring framework and this is it that begin the connection. So when i am into a controller. I have not access to the transaction object. Is it possible to get the current session in other way, without begin an other one?

Thank you...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 2:55 am 
Newbie

Joined: Mon Aug 15, 2005 11:25 am
Posts: 10
Sorry,
I am not very clear :

I am working with the spring framework and this is it that begin the transaction. So when i am into a controller. I have not access to the transaction object. Is it possible to get the current transaction with an other way, without begin an other one?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 5:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Specify a Tx manager lookup property in your config, but tt won't work if you are outside a JTA context.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 7:35 am 
Newbie

Joined: Mon Aug 15, 2005 11:25 am
Posts: 10
Ok

But how can I know if I am in a JTA context?

Here is a part of my application-context.xml file :

Code:
   <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
   <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory"><ref local="sessionFactory"/></property>
   </bean>

   <bean id="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
       <property name="sessionFactory"><ref local="sessionFactory" /></property>
      <property name="flushMode">
         <bean id="org.springframework.orm.hibernate3.HibernateAccessor.FLUSH_AUTO" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"/>
      </property>
   </bean>

   <bean id="hibernateDataAccessObject" class="com.evidence3.core.dao.hibernate.HibernateDataAccessObject">
      <property name="sessionFactory"><ref local="sessionFactory"/></property>
   </bean>

   <bean id="daoTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="target"><ref bean="hibernateDataAccessObject"/></property>
      <property name="transactionManager"><ref local="transactionManager"/></property>
      <property name="transactionAttributes">
         <props>
            <prop key="*">PROPAGATION_REQUIRED</prop>
         </props>
      </property>
        <property name="preInterceptors">
            <list>
                <ref bean="testInterceptor"/>
            </list>
        </property>
   </bean>


Must I inject the daoTransactionProxy bean to the hibernateDataAccessObject ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.