-->
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.  [ 7 posts ] 
Author Message
 Post subject: Does my Session object have an active transaction?
PostPosted: Wed Jun 23, 2004 1:05 pm 
Newbie

Joined: Thu May 20, 2004 6:34 pm
Posts: 8
Given a Hibernate Session, how can I determine if session.beginTransaction() has been called? Ultimately I would find it handy if there were a session.isInTransaction() method, but I can't find any way to get this information in the Session interface or in the SessionImpl interface, nor do I see any way to this information through an Interceptor.

As an aside, if beginTransaction is called, but no commit() or rollback() is called before the session is flush()'ed and close()'ed, what is the net effect? Is it the equivalent of a rollback()? Or a commit()? Or are the actions which took place in the transaction left in some sort of dysfunctional limbo?

Thanks in advance,

Frank

_________________
Frank Kurzawa


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 4:56 pm 
Newbie

Joined: Thu May 20, 2004 6:34 pm
Posts: 8
I'm asking about these things for the following two reasons:
1. I'm finding that my database updates and inserts are not being persisted to the database unless I explicitly begin a transaction and commit() it. This is true even though I already explicitly flush() and close() the Hibernate session. This makes me wonder if there is a transaction that is already opened in my session that I'm unaware of when I flush() and close() it.
Why would there be a transaction already open? I don't know - I've already gone over my code with a fine toothed comb and found nothing suspicious, and AFAIK Hibernate isn't beginning a transaction in my session behind my back either.

2. I am seeing an anomaly on my database machine. If I do a 'ps -efl', I find a postgres process in an 'idle waiting on transaction' state. It will wait forever until I shut down my tomcat instance. Based on the time that the process is started, it appears that this transaction is begun during Tomcat startup. I'm wondering if this is an uncommitted transaction that was begun in Hibernate's own startup and initialization code, but I haven't been able to determine where.

Thanks for any advice on how to track these down.

Regards,

Frank

_________________
Frank Kurzawa


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 5:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate ALWAYS returns connections with an active transaction (ie. autocommit off). Search the forum.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 6:20 pm 
Newbie

Joined: Thu May 20, 2004 6:34 pm
Posts: 8
My humble thanks Gavin,
FWIW, I've done quite a bit of forum searching,but it wasn't until I searched with the phrase "autocommit off" that I came up with the response to ALWAYS USE TRANSACTIONS. Now I see lots of posts that say (for example), "We've told you hundreds of times to always use transactions." It' just takes the right magic search criteria to find them.

I'm still confused why a session is left in "idle in transaction" at Tomcat startup time. This is apparently not in a session opend by me or accessible to me and it looks very suspicious to my naive mind. I'm not clear why Hibernate would want to leave a session and transaction open all the time. Do I need to worry about it? Or am I missing something basic?

Regards,

Frank

_________________
Frank Kurzawa


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 6:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Whenever you end a session, you also have to commit a txn, as per the doco.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 7:59 pm 
Newbie

Joined: Thu May 20, 2004 6:34 pm
Posts: 8
Thanks, now that I am doing that, the startup 'idle in transaction' is gone as well.

Honestly, I have read the docs countless times. Still don't know where it says that I must always commit a transaction. I thought it was sufficient to flush() and close() the session if I had never begun a transaction. :(

Guess I'll go back and look again. :)

Regards,

Frank

_________________
Frank Kurzawa


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 23, 2004 10:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Also try reading the FAQ.


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