-->
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: Just close Hibernate session in a read only transaction?
PostPosted: Tue Mar 01, 2016 2:57 am 
Newbie

Joined: Thu Mar 21, 2013 3:15 am
Posts: 5
Hi all,

In general, it is recommended to always a commit a session. When using a Hibernate session that performs selects statement only, is it a good idea to just close the session without committing or performing a rollback? Can anybody roughly point out the side effects of not committing the session in this case?

Thanks in advance.

Best regards,
Niko


Top
 Profile  
 
 Post subject: Re: Just close Hibernate session in a read only transaction?
PostPosted: Tue Mar 01, 2016 3:05 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You should always end a transaction (either commit or roll back), otherwise locks might be held and hinder scalability.


Top
 Profile  
 
 Post subject: Re: Just close Hibernate session in a read only transaction?
PostPosted: Tue Mar 01, 2016 3:10 am 
Newbie

Joined: Thu Mar 21, 2013 3:15 am
Posts: 5
Yes, this is also what I just read this morning, but this case affects metadata locking which is not a common use case. I particularly interested in table/row locks.
So to sum it up, just closing a Hibernate session doesn't trigger anything automatically and leaves resources open?

Regards,
Niko


Top
 Profile  
 
 Post subject: Re: Just close Hibernate session in a read only transaction?
PostPosted: Tue Mar 01, 2016 4:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Hibernate disables auto-commit, so when you obtain a connection, the JDBC driver will also start a database transaction too.
Behind the scenes, when you close the Session, Hibernate will propagate the close to the logical connection too (unless it is a shared Session).
Depending on the JDBC driver, the underlying transaction might nor might not end.

As a rule of thumb, is always better to end the transaction explicitly.


Top
 Profile  
 
 Post subject: Re: Just close Hibernate session in a read only transaction?
PostPosted: Tue Mar 01, 2016 4:31 am 
Newbie

Joined: Thu Mar 21, 2013 3:15 am
Posts: 5
Thank you for this clarification!


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.