# Upgrade from 5.4.10 to 5.4.11 up throws LazyInitializerException from Envers ToOneIdMapper

**URL:** <https://discourse.hibernate.org/t/upgrade-from-5-4-10-to-5-4-11-up-throws-lazyinitializerexception-from-envers-tooneidmapper/4473>\
**Category:** Hibernate ORM\
**Created:** [August 8, 2020, 5:15am UTC](https://discourse.hibernate.org/t/upgrade-from-5-4-10-to-5-4-11-up-throws-lazyinitializerexception-from-envers-tooneidmapper/4473 "2020-08-08T05:15:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jing.li](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@jing.li](https://discourse.hibernate.org/u/jing.li)\
**Post date:** [August 8, 2020, 5:15am UTC](https://discourse.hibernate.org/t/upgrade-from-5-4-10-to-5-4-11-up-throws-lazyinitializerexception-from-envers-tooneidmapper/4473/1 "2020-08-08T05:15:29Z")

</div>

We use Hibernate envers to audit our data. Our app works find with 5.4.10, but could not upgrade to 5.4.11 because that the class ToOneIdMapper was being changed in 5.4.11 by adding the code:

```auto
if ( lazyMapping && entity instanceof HibernateProxy ) {
			entity = ( (HibernateProxy) entity ).getHibernateLazyInitializer().getImplementation();
	}

```

We have the following entities:

```auto
@Entity
@Audited
public class A1 {
  @ManyToOne(fetch = FetchType.LAZY)
  @Approved
  private A2 a2;
  ...
}

@Entity
@Audited
public class A2 {
  @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @JoinColumn(name = "a3_id")
  private A3 a3= new A3();
  ...
}

@Entity
@Audited
public class A3 {
  String name;
  ...
}

```

The test use case is:

1. loading an A2 from database using currentSession.load
2. loading an A1 from database using currentSession.load
3. updating the A1 by setting the loaded A2 to the A1’s a2.
4. committing

The error happens during the committing:

```auto
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy [A3#6fbe8b74-c226-4121-87d7-863d58f6f5f2] - no Session
        at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:170) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:310) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.envers.internal.entities.mapper.relation.ToOneIdMapper.mapToMapFromEntity(ToOneIdMapper.java:62) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper$1.run(MultiPropertyMapper.java:137) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper$1.run(MultiPropertyMapper.java:105) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_242]
        at org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper.mapToMapFromEntity(MultiPropertyMapper.java:104) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.envers.internal.synchronization.work.CollectionChangeWorkUnit.generateData(CollectionChangeWorkUnit.java:54) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.envers.internal.synchronization.work.AbstractAuditWorkUnit.perform(AbstractAuditWorkUnit.java:66) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.envers.internal.synchronization.AuditProcess.executeInSession(AuditProcess.java:125) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.envers.internal.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:174) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.envers.internal.synchronization.AuditProcessManager$1.doBeforeTransactionCompletion(AuditProcessManager.java:47) ~[hibernate-envers-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:954) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:525) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2379) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101) ~[hibernate-core-5.4.19.Final.jar:5.4.19.Final]
        ... 137 more

```

It seems when envers generates audit data for A1, it goes through A2 and A3 as well.

We have spent a lot of time on this upgrading issue. We have not figure out why the session is closed.

The use case stopped us to upgrading our app with newer Hibernate release. So we post our issue here and ask for help.

Thank you very much,

Jing
