Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

spring hinbernet integration session problem

 
yogesh jarad
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to slove the org.hibernate.LazyInitializationException?

This is my spring-config.xml

 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic