• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

lazy="true" not working

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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" />
</set>
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

Mark
 
Rajan Nath
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark,
reply
    Bookmark Topic Watch Topic
  • New Topic