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

Hibernate JIRA | Jens Elkner | 1 decade ago
  1. 0

    hibernate seems do assume, that entities are always managed and I guess, that's why it does not serialize @Transient methods/fields. So unmanaged entities are not usable with hibernate! E.g. with: package test; @Entity @Table(name="languages") public class A_Language implements Serializable { private int id; private String name; private String code; // ... : getters and setters private Locale locale; @Transient public Locale getLocale() { if (locale == null && this.code != null && this.code.length() > 1) { locale = new Locale(this.code); } return locale; } @Transient public String getI18nName(Locale locale) { Locale l = getLocale(); String txt = l.getDisplayLanguage(locale); return txt.length() < 1 || txt.equals(this.code) ? this.name : txt; } } you'll get: 01:02:03,370 [AWT-EventQueue-0] ERROR (LazyInitializationException.java:19) - could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:50) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134) at test.A_Language$$EnhancerByCGLIB$$51b152ef.getI18nName(<generated>) IMHO @Transient does not mean @transient (at least EJB3 Spec does not mentioned this) ...

    Hibernate JIRA | 1 decade ago | Jens Elkner
    org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  2. 0

    hibernate seems do assume, that entities are always managed and I guess, that's why it does not serialize @Transient methods/fields. So unmanaged entities are not usable with hibernate! E.g. with: package test; @Entity @Table(name="languages") public class A_Language implements Serializable { private int id; private String name; private String code; // ... : getters and setters private Locale locale; @Transient public Locale getLocale() { if (locale == null && this.code != null && this.code.length() > 1) { locale = new Locale(this.code); } return locale; } @Transient public String getI18nName(Locale locale) { Locale l = getLocale(); String txt = l.getDisplayLanguage(locale); return txt.length() < 1 || txt.equals(this.code) ? this.name : txt; } } you'll get: 01:02:03,370 [AWT-EventQueue-0] ERROR (LazyInitializationException.java:19) - could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:50) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80) at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134) at test.A_Language$$EnhancerByCGLIB$$51b152ef.getI18nName(<generated>) IMHO @Transient does not mean @transient (at least EJB3 Spec does not mentioned this) ...

    Hibernate JIRA | 1 decade ago | Jens Elkner
    org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  3. 0

    SessionBean method returning POJO == exception? (EJB and other Java EE Technologies forum at JavaRanch)

    coderanch.com | 1 year ago
    org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    How can i wire-up org.springframework.transaction.interceptor.TransactionProxyFactoryBean and org.springframework.orm.hibernate3.HibernateInterceptor?

    Stack Overflow | 7 years ago | Wall-E
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
  6. 0

    Hibernate Community • View topic - object references an unsaved transient instance

    hibernate.org | 11 months ago
    org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.LazyInitializationException

      could not initialize proxy - no Session

      at org.hibernate.proxy.AbstractLazyInitializer.initialize()
    2. Hibernate
      CGLIBLazyInitializer.intercept
      1. org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:50)
      2. org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
      3. org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
      3 frames
    3. test
      A_Language$$EnhancerByCGLIB$$51b152ef.getI18nName
      1. test.A_Language$$EnhancerByCGLIB$$51b152ef.getI18nName(<generated>)
      1 frame