Skip to content

Regression: Session.Refresh on entity with lazy collection set throws LazyInitializationException #2457

Closed
@deAtog

Description

@deAtog

After upgrading to 5.3.1 from 4.0.4 we now get a LazyInitializationException when trying to refresh an entity with a lazy collection. The reason for the exception given is: no session or session was closed Minimal pseudo code to reproduce the issue is as follows:

public function CanRefreshEntity(int id) {
    using (ISession s = session_factory.OpenSession()) {
        EntityWithLazyCollection entity;

        using (ITransaction t = s.BeginTransaction()) {
            entity = s.Get<EntityWithLazyCollection>(id);
        }

        using (ITransaction t = s.BeginTransaction()) {
            // LazyInitializationException thrown here..
           s.Refresh(entity);
        }
    }
}

Pseudo xml mapping we are using is as follows:

<class name="EntityWithLazyCollection">
   <id name="Id" column="ParentId" generator="identity"/>
   <set name="Children" lazy="true" inverse="true" cascade="save-update">
      <key unique="true">
         <column name="ParentId" not-null="true"/>
      </key>
      <one-to-many class="Child"/>
   </set>
</class>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions