This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate: object presistent mapping question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: object presistent mapping question" Watch "Hibernate: object presistent mapping question" New topic
Author

Hibernate: object presistent mapping question

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Hello all:

After retrieving an object from the databse and closing the session, all other objects -attributes- that linked to this object become unavailable.

How can I make those objects available?

If I used "session.disconnect" they become available, however shouldn't I close the session after every database operation?

Thanks


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
H Ritwick
Greenhorn

Joined: Mar 15, 2006
Posts: 18
One of the solution may be is to use the HibernateSessionRequestFilter http://www.hibernate.org/43.html in which you commit the transaction and close the session only in the filter.

or if you really want to colse the session before the view is rendered then explicitly copy all the attributes required for the view to a custom dto.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

I close my sessions and the data is still available. Properties are all available as they are not lazy loaded or proxied. But for things which are lazy loaded such as collections, and for references to other persistent objects which will be proxied by default you need to load the collection or initialize the proxy.

Hibernate.initialize(object);

will make the object available after session close. If its a collection you need to iterate over the whole collection, or call size(). I have not been able to get initialize to make a collection available.
 
wood burning stoves
 
subject: Hibernate: object presistent mapping question
 
Similar Threads
Part 2: persistent messages vs database storage
storing mbs on session doubt
What does a SessionFactory object cache?
Hibernate Session.evict() with pesistent childs
Binding user objects to request,session,pagecontext, application