File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with LazyInitializationException

 
Muhammad Ramahy
Greenhorn
Posts: 11
Eclipse IDE jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get this exception:


every time I try to execute this code:


I don't know what to do in order to avoid not having session or having multiple sessions and I wish Help

Regards,
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception is caused due to detached object. You will have to use session.merge() or session.lock() to attach the object to the session.

http://stackoverflow.com/questions/912659/what-is-the-proper-way-to-re-attach-detached-objects-in-hibernate
 
Muhammad Ramahy
Greenhorn
Posts: 11
Eclipse IDE jQuery Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works! thank you, I would also want to say that if I've added to the oneToMany annotation it will also work (that's what I'm currently doing).
 
nivedan Nat
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

But adding FetchType.Eager defeats the purpose of Lazy Loading. Depends where your using this object, probably associate the entity into session so that lazy loading can happen.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic