wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Problem with LazyInitializationException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with LazyInitializationException" Watch "Problem with LazyInitializationException" New topic

Problem with LazyInitializationException

Muhammad Ramahy

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

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.

Muhammad Ramahy

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

Joined: Jul 22, 2011
Posts: 2

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.
jQuery in Action, 2nd edition
subject: Problem with LazyInitializationException
Similar Threads
hibernate.AssertionFailure collection [] was not processed by flush()
org.hibernate.MappingException : Unknown Entity?
Hibernate 3: java.sql.SQLException: Field 'passwordConfirmation' doesn't have a default value
Sql Exception: inconsistent datatypes, need help
How to create a new excel file on server