It's not a secret anymore!
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: object presistent mapping question" Watch "Hibernate: object presistent mapping question" New topic

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?


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

Joined: Mar 15, 2006
Posts: 18
One of the solution may be is to use the HibernateSessionRequestFilter 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.


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.
I agree. Here's the link:
subject: Hibernate: object presistent mapping question
It's not a secret anymore!