• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

LazyInitializationException : Unable to retrieve values from Database sometimes .

 
Ranch Hand
Posts: 70
Android Hibernate Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am trying to access the values in Beneficiary_Details table using the following function (Hibernate) .




The values of the table are getting retrieved when I keep breakpoints and make some delay to execute but only NULL values are getting retrieved when I execute it all of sudden.

I am getting error in Console as :

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed




Please help me to solve this issue !
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you code looks a bit more complicated than it needs to be. I am also not sure why you are using Vectors and Arrays.

To your question though.

You will get this exception if you try to access unfetched data outside of a session context.

A few possible solutions:

1. You can either make sure you only access this when the session is still open
2. Trigger a lazy load before while the entity is still attached (i.e. by accessing the lazily loaded propertes)
3. Change your Fetch strategy to Eager
4. Change your HQL to eagerly fetch (look at the fetch keyword)

See Fetching strategies
 
We begin by testing your absorbancy by exposing you to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic