-->
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: when to start and end a session?
PostPosted: Thu Dec 06, 2007 9:08 am 
Newbie

Joined: Tue Nov 27, 2007 6:11 am
Posts: 12
Hi all,
I have a lot of persistent objects that must be loaded, edited and then saved thru a GUI. Actually, all my objects have a load and save method that performs SQL query against a database, performing an hand-crafted bmp. Now I'm moving to hibernate, and I'd like to know if I should start the session when I load all the object and keep it active until the GUI is opened (saving objects as needed) or should I open a session and close it only when I need to save the objects? Any suggestion?

Thanks,
Luca


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 1:14 pm 
Newbie

Joined: Thu Dec 06, 2007 12:57 pm
Posts: 2
you don't need to close the session to save your objects. that's what the commit is for. you should be able to keep a session open to do as many commits as you need. if you are not sure at commit time whether you have an open session or not, you can use the .isOpen() method. if you find an open session, you can use .getCurrentSession(), otherwise you need to .openSession(). when you are done with your commits and don't really need a session, that might be a good time to close the session. one way to think of a session is to compare it to a door and the database to a room. as long as a door is open, you can put things into the room. you don't always need to follow 'open door, put stuff in, close door'. it makes sense to close the door when you are done putting the stuff in. hope that helps!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 1:35 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

read this
http://www.hibernate.org/42.html

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 08, 2007 8:34 am 
Newbie

Joined: Tue Nov 27, 2007 6:11 am
Posts: 12
ramnath wrote:


Ok, let me see if I get it right. When I start loading all my business objects in order to show them to the user, then I start a session and a transaction, that ends as soon as the loading finishes. Then, when the user wants to change an object, I start another transaction within the same session, and commit/rollback it. Once the user exits from the GUI editing panel, I close the session. Could it work like this?
What if I've got several panels for editing different kinds of objects, do you recommend opening new sessions for all of them or keeping a single session for the whole application?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 08, 2007 1:44 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

Use seperate session, basically after the first hit from the DB, you will have the data from the cache...so it is safe to do it that way...

Hope it helps:-)

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


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.