Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: object presistent mapping question

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
H Ritwick
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic