org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: test.lazysetinit.Record.titles, no session or session was closed

Hibernate JIRA | Artur Jonak | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I have an entity which can have multiple titles located in a separate table. I mapped this as a set where key attribute references other property of the entity: <set name="titles" table="TTitle" cascade="none" lazy="true" inverse="true" mutable="false"> <key column="ID" property-ref="parentId"/> <!--key column="ID"/--> <element type="string" column="title"/> </set> when I try to display this set I get an exception: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: test.lazysetinit.Record.titles, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) ... The entire mapping is as follows: <class name="Record" table="TRecord" mutable="false"> <id name="id" type="long"> <column name="ID" sql-type="number" length="12" not-null="true" unique="true"/> </id> <set name="titles" table="TTitle" cascade="none" lazy="true" inverse="true" mutable="false"> <key column="ID" property-ref="parentId"/> <!--key column="ID"/--> <element type="string" column="title"/> </set> <join table="TRecordInfo" inverse="true" fetch="join" optional="false"> <key column="ID"/> <property name="parentId" not-null="false" /> <property name="status" /> </join> </class> Attached the test case: test.lazysetinit.LazySetInitTest. DB schema is located in test/conf/lazysetinit/schema.sql Regards, Artur

    Hibernate JIRA | 1 decade ago | Artur Jonak
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: test.lazysetinit.Record.titles, no session or session was closed
  2. 0

    I have an entity which can have multiple titles located in a separate table. I mapped this as a set where key attribute references other property of the entity: <set name="titles" table="TTitle" cascade="none" lazy="true" inverse="true" mutable="false"> <key column="ID" property-ref="parentId"/> <!--key column="ID"/--> <element type="string" column="title"/> </set> when I try to display this set I get an exception: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: test.lazysetinit.Record.titles, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) ... The entire mapping is as follows: <class name="Record" table="TRecord" mutable="false"> <id name="id" type="long"> <column name="ID" sql-type="number" length="12" not-null="true" unique="true"/> </id> <set name="titles" table="TTitle" cascade="none" lazy="true" inverse="true" mutable="false"> <key column="ID" property-ref="parentId"/> <!--key column="ID"/--> <element type="string" column="title"/> </set> <join table="TRecordInfo" inverse="true" fetch="join" optional="false"> <key column="ID"/> <property name="parentId" not-null="false" /> <property name="status" /> </join> </class> Attached the test case: test.lazysetinit.LazySetInitTest. DB schema is located in test/conf/lazysetinit/schema.sql Regards, Artur

    Hibernate JIRA | 1 decade ago | Artur Jonak
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: test.lazysetinit.Record.titles, no session or session was closed
  3. 0

    Hibernate Collection Initailization issue

    Stack Overflow | 8 months ago | Aksanth
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.MainData.association, no session or session was closed
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Hibernate org.hibernate.LazyInitializationException

    Stack Overflow | 5 years ago | varsha
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ecomm.ultimatesms.messaging.persistence.pojos.Mno.startnumbers, no session or session was closed

    Root Cause Analysis

    1. org.hibernate.LazyInitializationException

      failed to lazily initialize a collection of role: test.lazysetinit.Record.titles, no session or session was closed

      at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException()
    2. Hibernate
      AbstractPersistentCollection.read
      1. org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
      2. org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
      3. org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
      4. org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
      4 frames