• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

spring hinbernet integration session problem

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to slove the org.hibernate.LazyInitializationException?

This is my spring-config.xml

 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy, Yogesh. Welcome to JavaRanch!

Champ, I'd kindly like to ask you to put your code between [code][/code] tags whenever you post code. I edited your post and included these tags. UseCodeTags

Now, you somewhere have a OneToMany relationship, right? Try changing its fetch mode to eager initialization and let us know if it works.
 
ranger
Posts: 17346
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
Actually, while you can change your mapping to eager, that is not the best way or the best approach. Eager fetching should be set at query time, never in mapping. If you put it in mapping you will get rid of any LazyInitializationException, but you will slow down your use cases that don't need all that data. You would be getting too much data from the database and have to trasnfer all that data on the wire when that particular use case might not need it.

Fetch mode should always be a query time thing.

LazyInitializationException occurs when you haven't fetched all the data you need and you close the Session and then try to access that data not fetched. Since Hibernate will have proxies for that data, then it will try to connect to the database but since there is no Session there is no Connection to the database to get that other data.

Also, this is a Hibernate question, not a Spring question so should have been posted in the ORM forum.

Mark
 
Mark Spritzler
ranger
Posts: 17346
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
Sorry, I deleted your other thread about Open Session In View. While that also would work, you are still adding patches to the actual problem of not getting exactly the amount of data your use case needs at the time of query and waiting till the jsp page to do more querying.

Mark
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic