-->
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: Transaction context
PostPosted: Mon Jun 14, 2004 8:43 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 8:22 am
Posts: 28
When my Stored Procedures are executed and I throw an exception, the data stored in the SP don't roll back.

My question is... using the connection obtained through the session, would it be in the same transaction of the session?

Sample:

try
{
getSession().beginTransaction();

// ....

Connection conn = session.connection();
CallableStatement callStmt = conn.prepareCall(chamada);
stmt.executeUpdate();

// ..... (manipulate objects..)

getTransaction().commit();
}catch(Exception ex)
{
getTransaction().rollback();
}


Thanks

_________________
Ricardo K. Costa


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 12:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes it is, since it's the same connection

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 1:06 pm 
Beginner
Beginner

Joined: Tue Feb 10, 2004 8:22 am
Posts: 28
So I don't understand what is happening... the SP doesn't have "commit" and the data inserted into the SP isn't rolled back when ocurring an exception.

Any idea? I tried to set the autocommit false into the connection, it worked, but doesn't make sense and the data take too long to be commited at all.

_________________
Ricardo K. Costa


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 6:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
autocommit *must* be set to false, and you transaction be explicit using bsession.beginTransaction and tx.commit(); otherwise you"re not in the same tx, since the JDBC driver will create a new one for every single statement.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 9:04 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 8:22 am
Posts: 28
Thank you very much, Emmanuel!
It's clearer now. :)

Just one more doubt... like I told before it works when I set the autocommit to false, but after the process finish to run the table keeps locked and the data take a while (5 - 10 seconds) to appear into the DB.

Is it usual to happen that? It's just a small register hardcoded inserted in a table in the SP. When I make conn.commit doesn't have this delay.

Thanks again.

_________________
Ricardo K. Costa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 10:23 am 
Beginner
Beginner

Joined: Tue Feb 10, 2004 8:22 am
Posts: 28
Solve it! :)
Thanks everybody!

Now it was my mistake...

It works like expected. :)

_________________
Ricardo K. Costa


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.