lundi 29 août 2016

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

org.hibernate.LazyInitializationException: could not initialize proxy - no Session
 org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
 org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
 org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)


This problem occurs when you have a relation between tow tables.
Your objects are lazy initialized. That's mean, they are initializing only on demand on non-closed session. 
To resolve this exception add laze=false  into you mapping file or  change FetchType.LAZY to FetchType.EAGER
if you use annotation.

In fact,the EAGER strategy is a requirement on the persistence provider runtime that data must be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime that data should be fetched lazily when it is first accessed.