| Author |
Problem with LazyInitializationException
|
Muhammad Ramahy
Greenhorn
Joined: Jun 14, 2011
Posts: 11
|
|
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
Joined: Aug 11, 2010
Posts: 218
|
|
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
Joined: Jun 14, 2011
Posts: 11
|
|
|
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
Joined: Jul 22, 2011
Posts: 2
|
|
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.
|
 |
 |
|
|
subject: Problem with LazyInitializationException
|
|
|