-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate 3.1 Transaction != Hibernate 3.0.5 Transaction???
PostPosted: Fri Dec 30, 2005 9:38 am 
Newbie

Joined: Wed Dec 28, 2005 9:18 am
Posts: 4
The 'nested transaction' is not working at the Hibernate 3.1? At least not as it was at Hibernate 3.0.

Below there is a test that works perfectly at Hibernate 3.0, but not at Hibernate 3.1.

Another test a bit more elaborated:
Code:

   Session session = BaseRootDAO.getSession(true);
         Transaction t = session.beginTransaction();
         
         TesteDao dao = new TesteDao();
         try{
         
            Cliente cli = new Cliente();
            //set valores clientes
            
            dao.saveOrUpdate(session, cli);
            
            Dependente dep = new Dependente();
            //set valores dep
            
            dao.saveOrUpdate(session, dep);
         
         
           t.commit();//All changes need to be sent to the db in this line.
                 //As inside the DAO the transation was already openned at the session
                 //that it receives as parameter, then the commit inside the DAO
                 //must not to send the datas to the db that is a transation
                 //transação nestled
         }catch(Exception e){
             t.rollback();
             e.printStackTrace();
         }



Méthod SaveOrUpdate of the DAO.
Code:
   public void saveOrUpdate(Session s, Object obj) throws HibernateException {
      Transaction t = null;
      try{
         t = s.beginTransaction();//Como a sessão recebida por parametro já tinha
                   //uma transação aberta, está transação que esta abrindo
                   //agora deveria se tornar uma transação aninhada a primeira
         
         s.saveOrUpdate(obj);

         t.commit();//Esse commit não deve levar as informações para
               //O banco de dados pois ela é uma transação aninhada.
               //Ele só comita realmente se a Session recebida como parametro
               //não tivesse nenhuma transação aberta. Com o hibernate 3.1 ele
               //está comitando essas informações no Banco.
      }catch (HibernateException e) {
         if (null != t) t.rollback();
              throw e;
      }
   }



I made this test with the Hibernate 3.0 and it works. The informations are only commiteds really at the db an th end of the first method, after this I just eu só changed Jar to the 3.1 and the infomations are comitteds inside the SaveOrUpdate of the DAO, make the teste.

Thanks for the help. [/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 10:00 am 
Newbie

Joined: Wed Dec 28, 2005 9:18 am
Posts: 4
I forgot to translate the DAO

Code:
public void saveOrUpdate(Session s, Object obj) throws HibernateException {
       Transaction t = null;
       try{
          t = s.beginTransaction();/*How a section received by parameter already had a open transaction, this
transaction should be a nested transaction of the first one.*/           
          s.saveOrUpdate(obj);
 
          t.commit();/*He only commit wheter a receveid session as a
parameter didn´t have any opened transation. With the Hiobernate 3.1, the
informations are commiting in the data base.*/
       }catch (HibernateException e) {
          if (null != t) t.rollback();
               throw e;
       }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 11:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
what is you tx factory in this example

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 11:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
AFAIK neither JTA nor plain JDBC support neested Tx anyway

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 1:47 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Move transaction demarcation code out of DAO


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.