Hibernate trying to use an already closed session

org.hibernate.LazyInitializationException
Javadoc
Indicates an attempt to access not-yet-fetched data outside of a session context. For example, when an uninitialized proxy or collection is accessed after the session was closed. @see Hibernate#initialize(java.lang.Object) @see Hibernate#isInitialized(java.lang.Object) @author Gavin King
at org.hibernate.proxy.AbstractLazyInitializer.initialize
(source)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation
(source)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke
(source)

Typical Exception Messages

  1. could not initialize proxy - no Session
  2. could not initialize proxy - no Session
  3. could not initialize proxy - the owning Session was closed
  4. could not initialize proxy - no Session
  5. could not initialize proxy - no Session
  6. could not initialize proxy - the owning Session is disconnected
  7. could not initialize proxy - no Session
  8. could not initialize proxy - no Session] with root cause org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  9. could not initialize proxy
  10. could not initialize proxy [com.mb.push.model.ApiKey#1] - no Session

Origin

AbstractLazyInitializer.getImplementation() has thrown a LazyInitializationException

org.hibernate.LazyInitializationException
1 frames hidden
org.hibernate.proxy.AbstractLazyInitializer.getImplementation
201Web pages

Similar

Specific cases

Solution

rahsan, 2 months ago

You are trying to use a session that has been closed after the most recent transaction. To resolve this issue check this solution

If you are using Spring just adding @Transactional annotation to your methods(where you use Hibernate/JPA operations) will allow Spring to handle session management and avoid such errors.

External results for this pattern (129)

  1. maximehammvia GitHub1 month ago
    could not initialize proxy - no Session
    Show stack trace
  2. jean-pierre jean-pierrevia Hibernate JIRA2 months ago
    could not initialize proxy - no Session
    Show stack trace
  3. Amirvia Stack Overflow3 months ago
    could not initialize proxy [com.mb.push.model.ApiKey#1] - no Session
    Show stack trace
  4. Jason Savellvia Sakai JIRA3 months ago
  5. Durga Duttvia Stack Overflow3 months ago
    could not initialize proxy - no Session
    Show stack trace
  6. Quirijnvia Tridion3 months ago
    could not initialize proxy - no Session
    Show stack trace
  7. Pikovia Stack Overflow3 months ago
    could not initialize proxy - no Session
    Show stack trace
  8. could not initialize proxy - no Session
    Show stack trace