Hibernate Envers listeners fail because EntityManager is closed when using JPA/JTA/Hibernate 5.2.8/Envers

Description

My environment:

Using spring with JPA + JTA and Hibernate 5.2.8.Final + Envers

The problem is that Springframework ORM (JPA subpackage) closes the entity manager During

step.

When the Hibernate envers listeners are triggered (during

step), the entity manager is already closed.

In hibernate 4.x there's no problem because the EntityManager and hibernate Session are two different instances and closing the entity manager won't always close the hibernate session. In hibernate 5.2.x they are the same instance.

I created a small setup where I can reproduce the issue. Please find it attached.
Main class:

This was originally reported in spring:
https://jira.spring.io/browse/SPR-15334

https://jira.spring.io/browse/SPR-15334?focusedCommentId=136067&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-136067

Environment

None

Activity

Show:
Jones
March 14, 2017, 10:40 AM

Additional information: I tested with Narayana 5.5.3.Final (instead of Atomikos) and I faced the same issue

Jones
March 20, 2017, 1:00 PM

The fix for this issue considered only one possible failure when executing Hibernate Envers Listeners

I'm getting other failures as you can see below:

Envers listeners try to initialize relationships as well, and the session is closed.

Should I report this in a separate issue?

Andrea Boriero
March 20, 2017, 1:37 PM

Hi ,

yes please, can you open a separate issue with a test case?

Thanks

Jones
March 20, 2017, 4:06 PM

The following issue: was created

Andrea Boriero
March 20, 2017, 4:23 PM

Thanks

Assignee

Andrea Boriero

Reporter

Jones

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

4.3.11

Components

Affects versions

Priority

Major
Configure