-->
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.  [ 3 posts ] 
Author Message
 Post subject: Session.connection and transactions
PostPosted: Tue Sep 27, 2005 6:19 pm 
Newbie

Joined: Tue Sep 27, 2005 5:44 pm
Posts: 13
Hibernate version: 2.1

Name and version of the database you are using: Oracle 9i

Hello,

My question is whether a connection taken directly off of a Session object which is explictly part of a transaction also falls under that same transaction.

I open the session and begin the transaction with:

Session lSession = HibernateUtil.getSession();
Transaction tx = HibernateUtil.beginTransaction(lSession);

Within the code and before the transaction, tx, is commited is the following code:

Connection lConn = pSession.connection();
lPStmt = lConn.prepareStatement(lUpdSql);
lConn.execute();

The problem is that there is a trigger that is immediately executed as a result of the lConn.execute(); line of code. I was under the impression that triggers did not fire until the transaction is committed. It is not until later that the transaction is committed with:

HibernateUtil.commitTransaction(tx);

If the connection is part of the transaction then the backup question is how can the connection read uncommitted inserts? The trigger is throwing an exception because it is trying to verify a foreign key constraint for a newly inserted key that has not been committed but is in the same transaction.

Thank you kindly for any insight.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 10:45 pm 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
Yes, the connection is part of the same transaction - everything else would be unusable...

I suppose your problem is that the insert you've done have not been flushed to the database. Try flushing after the inserts - this should do the job.

Erik


Top
 Profile  
 
 Post subject: Session.connection and transactions
PostPosted: Fri Sep 01, 2006 12:26 pm 
Newbie

Joined: Tue Sep 27, 2005 5:44 pm
Posts: 13
Thanks Erik. Yes, that was the problem. Had to flush the session before and after using session.connection(). Probably in the docs...

As a side note, the dba Oracle (9i) noticed that the db would assign an extra session connection when using session.connection(), so that would be 2 connections in one txn. I'm assuming oracle facilitates commits and rollbacks over these 2 seperate connections?


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