-->
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: Hibernate Sessions + Proxy Loading
PostPosted: Fri Jul 27, 2007 5:08 pm 
Newbie

Joined: Sat Jul 14, 2007 6:02 pm
Posts: 8
I am writing an application that uses hibernate and postgres to store its information. There are a lot of pop up windows with combo box'es. I populate the combo boxes with objects from the DB.

My understanding of reading the doco. is that I should try and wrap units of work with open/close sessions.

Where I am having problems is something like

session.open
get list of object
<do I close the session here>
populate the combo box with the items
<or do I close the session here>
do stuff on the pop up window
window closes
session.close

My concern is that, lazy loading will not load all the information that I need in to the combo box and that when it comes time to access that information the session will be closed.


I have design it around pojo's and DAO. My thought it is to push all the getters/setters through the pojo into the dao and wrapper them around session.open / session.close - but that doesn't seem right either.


Alex


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 12:04 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
If the system will be used by multiple concurrent users then you shouldn't keep the session open while the user modifies data. So, open the session, retrieve the data and before you close the session, force hibernate to load any lazy collections/objects that will be needed in you popup.

When the user has finished making changes, open a new session and merge the changes back into the database.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 5:09 pm 
Newbie

Joined: Sat Jul 14, 2007 6:02 pm
Posts: 8
thatmikewilliams wrote:
If the system will be used by multiple concurrent users then you shouldn't keep the session open while the user modifies data. So, open the session, retrieve the data and before you close the session, force hibernate to load any lazy collections/objects that will be needed in you popup.

When the user has finished making changes, open a new session and merge the changes back into the database.


I understand that is the theory, one of my objects is attached via collections to just about the whole database. I guess I need a better understanding of lazy loads.

when i retireve an object which has a collection class associated with it, lazy loading I presume says load just the class and put place holders there for the collection. ?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 6:16 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
All collections are lazy by default unless specified otherwise in the mapping file/annotations or queries used to fetch the data (via fetch joins).

Individual objects may also be lazily loaded which has caught me out a few times. Unless you access one of the fields during the session (not necessarily a collection) then hibernate might not even load the root class from the database.

The challenge with lazy loading and detatched objects is identifying the data that is needed for a particular user-based operation. Although one of your objects might reference the entire database, its unusual for any given user operation to be able to view/modify that complete data set. Normally its constrained to an individual entity or group of entities (items/orders/users/etc.).

You might end up with several different DAO methods to retrieve the same core object but initialise different collections depending on the situation.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 29, 2007 8:53 pm 
Newbie

Joined: Sat Jul 14, 2007 6:02 pm
Posts: 8
Yep that is getting to be my understanding, I have gone through my code and placed opensession, update (object), access object, close session when I am building info.

My next hurdle in this is threads and sessions, I have a thread session manager, I have my own access mething to get the session, but it doles out the same session in use to different threads - is that going to be a problem - I presume so (i read the sessions aren't thread safe). but my other problem which brought me to this was not have an object in to sessions !

I have a jframe with panels (about 8), each panel is getting updated by its own thread, all the threads talk back to the same database.

Alex


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 12:18 am 
Regular
Regular

Joined: Wed Apr 25, 2007 11:44 pm
Posts: 59
dude try this one

http://www.hibernate.org/43.html (Open Session in View)

might help you

you should also read http://www.hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 30, 2007 2:51 am 
Newbie

Joined: Sat Jul 14, 2007 6:02 pm
Posts: 8
I will have to check out disconnects

thanks


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.