I have a problem with Hibernate Enverse (Version 5.2.0-Final).
Context: I’m auditing some entities with some lazy relations. I have a jsf-page that loads one version of one entity with all relations of that version. That works fine. So now I have a page that shows a revision of the entity with all relations of that revision. On this page I can open a fieldset, that triggers an AJAX. In this request we reattach all relations by calling entityManager.merge(entity)
to be able to fetch the lazy relations in this fieldset.
The Problem: The AJAX is a new request. The server calls entityManager.merge(entity)
, what enforces creation of a new EntityManager (So a new org.hibernate.internal.SessionImpl
is created). On this object hibernate calls SessionImpl.merge(...)
. But in the method org.hibernate.internal.AbstractSharedSessionContract.createQuery(String)
a other SessionImpl object is used, which is already closed. That enforces an java.lang.IllegalStateException: Session/EntityManager is closed
.
In one sentence : Although a new entityManager was created and a merge was called on that new entityManger, Hibernate uses an old Session/EntityManager of the request before.
I debugged the problem and found following:
- Debug1: Shows the Stacktrace of the SessionImpl.merge with the session’s object id
- Debug2: Shows the last method with the correct SessionImpl object (see it’s id). This object is not used in next methods.
-
Debug3: The step after Debug2 does not know the given SessionImpl object. It has it’s own SessionImpl object in
collection.initializor.versionsReader
. This session was created and closed in the request before (on loading the page). - Debug4: Now Hibernate wants to create the query wit the closed SessionImpl
- Debug5: This enforces the exception, as the session is closed.
My questions :
- Is this a bug of Hibernate?
- Why is the given SessionImpl in method
org.hibernate.type.CollectionType.getElementIterater(...)
not used? - Anyone knows a solution or workaround for this problem?
Tank you very much for any idea. I spent days on this bug.