permaculture playing cards
The moose likes Object Relational Mapping and the fly likes lazy= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "lazy="true" not working" Watch "lazy="true" not working" New topic

lazy="true" not working

Rajan Nath

Joined: Nov 27, 2007
Posts: 22
when ever I try to use lazy="true" ( as I want child should not load) , recevied exception
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.Folder.messages, no session or session was closed
the entry in hbm like
<set name="messages" table="folder_msg" lazy="true" cascade="none" sort="natural">
<key column="fld_id" />
<many-to-many class="Message" column="msg_id" />
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17271

Hi Rajan.

Actually, that error message you got means that lazy="true" is completely working, it means that the collection is not loaded because it is lazy, and then you are trying to access the collection, which isn't loaded, outside of a session.

When you have a lazy collection, when you go to access the collection, Hibernate will want to go to the database to get the data, but since there is no Session (which holds the connection object) there is no way to access the database, so it throws that exception


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rajan Nath

Joined: Nov 27, 2007
Posts: 22
Thanks Mark,
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: lazy="true" not working
jQuery in Action, 3rd edition