org.hibernate.LazyInitializationException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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
    via by Artur Jonak,
  • 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
    via by Artur Jonak,
  • Hibernate Collection Initailization issue
    via Stack Overflow by Aksanth
    ,
  • LazyInitializationException
    via by bobfromdy,
  • Why Hibernate Eager Fetch Does Not Work?
    via Stack Overflow by user1007852
    ,
    • 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)

    Users with the same issue

    Unknown visitor1 times, last one,
    mauritius
    2 times, last one,
    treefolk
    2 times, last one,
    mortalman7
    1 times, last one,
    Unknown visitor1 times, last one,
    9 more bugmates