[JIRA] (HHH-14061) No session exception with entityManager.clear() with Envers in JTA transaction
by LAdO (JIRA)
LAdO ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYWY4NzA0ODVi... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14061?atlOrigin=eyJpIjoiYWY4Nz... ) HHH-14061 ( https://hibernate.atlassian.net/browse/HHH-14061?atlOrigin=eyJpIjoiYWY4Nz... ) No session exception with entityManager.clear() with Envers in JTA transaction ( https://hibernate.atlassian.net/browse/HHH-14061?atlOrigin=eyJpIjoiYWY4Nz... )
Issue Type: Bug Assignee: Chris Cranford ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) Components: hibernate-envers Created: 05/Jun/2020 00:00 AM Priority: Major Reporter: LAdO ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
HHH-13760 ( https://hibernate.atlassian.net/browse/HHH-13760 ) causes regression under specific conditions.
When entityManager.clear() is called in a JTA transaction with FlushMode.MANUAL, the changed entity must have a @ManyToOne Lazy reference and must add or remove an item from the @OneToMany collection.
An error occures after entityManager.close() and commit (simulates spring jta transaction).
>
>
>
> ...
> Caused by: org.hibernate.LazyInitializationException: could not initialize
> proxy org.hibernate.envers.test.entities.onetomany.SetRefIngEntity#3 ( #3 )
> - no Session
> at
> org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:170)
>
> at
> org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:310)
>
> at
> org.hibernate.envers.internal.entities.mapper.relation.ToOneIdMapper.mapToMapFromEntity(ToOneIdMapper.java:62)
>
> at
> org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper$1.run(MultiPropertyMapper.java:137)
>
> at
> org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper$1.run(MultiPropertyMapper.java:105)
>
> at java.security.AccessController.doPrivileged(Native Method)
> at
> org.hibernate.envers.internal.entities.mapper.MultiPropertyMapper.mapToMapFromEntity(MultiPropertyMapper.java:104)
>
> at
> org.hibernate.envers.internal.synchronization.work.CollectionChangeWorkUnit.generateData(CollectionChangeWorkUnit.java:54)
>
> at
> org.hibernate.envers.internal.synchronization.work.AbstractAuditWorkUnit.perform(AbstractAuditWorkUnit.java:66)
>
> at
> org.hibernate.envers.internal.synchronization.AuditProcess.executeInSession(AuditProcess.java:125)
>
> at
> org.hibernate.envers.internal.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:164)
>
> at
> org.hibernate.envers.internal.synchronization.AuditProcessManager$1.doBeforeTransactionCompletion(AuditProcessManager.java:47)
>
> at
> org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:954)
>
> at
> org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:525)
>
> at
> org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2379)
>
> at
> org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:447)
>
> at
> org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:355)
>
> at
> org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:47)
>
> at
> org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:37)
>
> at
> com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
>
> at
> com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:273)
>
> at
> com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:93)
>
> at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:164)
> at
> com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1165)
>
> ... 61 more
>
>
However, I'm not sure if the call to entityManager.close () is used correctly in this context.
( https://hibernate.atlassian.net/browse/HHH-14061#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14061#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100128- sha1:078e4e4 )
5 years, 6 months
[JIRA] (HHH-14060) "Illegal attempt to associate a collection with two open sessions" during test execution
by Martin Panzer (JIRA)
Martin Panzer ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ed8c2e... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODg4OWQyOGJl... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-14060?atlOrigin=eyJpIjoiODg4OW... ) HHH-14060 ( https://hibernate.atlassian.net/browse/HHH-14060?atlOrigin=eyJpIjoiODg4OW... ) "Illegal attempt to associate a collection with two open sessions" during test execution ( https://hibernate.atlassian.net/browse/HHH-14060?atlOrigin=eyJpIjoiODg4OW... )
Change By: Martin Panzer ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ed8c2e... )
**Describe the bug**
I am currently upgrading a project from hibernate 5.0.10 (wildfly 10), to hibernate 5.4.17 (quarkus).
The application itself works without any problems.
Test execution fails however on the new hibernate version.
I reduced the problem down to some strange session handling.
Inside "AbstractPersistentCollection.setCurrentSession", the sessions are not equal. The collection was created with the entitymanager (and therefore session) I use in my test, but the transaction commit happens with another session.
Further testing showed, that this regression was introduced somewhere between hibernate 5.1.17 and 5.2.0.
I attached an minimal reproducer project, which has hibernate 5. 4 2. 17 0 as dependency.
You can relativly easily switch it to 5. 0 1. 10 17 , where the tests execute correctly.
**Expected behavior**
No problems with test execution after the upgrade to hibernate 5. 4 2. 17 0.
**Actual behavior**
When I run my tests, I get the following exception. The test run is failed (red) in this case.
{code:java}
Jun 04, 2020 12:20:49 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [name: persistenceUnitExample]
Jun 04, 2020 12:20:49 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate ORM core version 5.4.17.Final
Jun 04, 2020 12:20:49 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
Jun 04, 2020 12:20:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jun 04, 2020 12:20:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [null] at URL [jdbc:h2:mem:test]
Jun 04, 2020 12:20:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {}
Jun 04, 2020 12:20:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jun 04, 2020 12:20:50 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Jun 04, 2020 12:20:50 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Jun 04, 2020 12:20:50 PM org.hibernate.resource.beans.spi.ManagedBeanRegistryInitiator resolveBeanContainer
INFO: HHH10005002: No explicit CDI BeanManager reference was passed to Hibernate, but CDI is available on the Hibernate ClassLoader.
Jun 04, 2020 12:20:50 PM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@3005db4a] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Jun 04, 2020 12:20:50 PM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@3013909b] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Jun 04, 2020 12:20:50 PM org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator initiateService
INFO: HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Jun 04, 2020 12:20:51 PM org.hibernate.collection.internal.AbstractPersistentCollection unsetSession
WARN: HHH000471: Cannot unset session in a collection because an unexpected session is defined. A persistent collection may only be associated with one session at a time. Collection : [<unreferenced>]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.642 s <<< FAILURE! - in org.acme.ExampleServiceTest
[ERROR] create Time elapsed: 0.666 s <<< ERROR!
javax.persistence.RollbackException: Error while committing the transaction
at org.acme.ExampleServiceTest.create(ExampleServiceTest.java:31)
Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions. Collection : [<unreferenced>]
at org.acme.ExampleServiceTest.create(ExampleServiceTest.java:31)
Caused by: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions. Collection : [<unreferenced>]
at org.acme.ExampleServiceTest.create(ExampleServiceTest.java:31)
{code}
**To Reproduce**
Steps to reproduce the behavior:
1. Download the attached reproducer project
2. Run "mvn clean test"
3. Tests failed.
4. In the pom.xml, change the hibernate-orm.version to 5. 0 1. 10 17.Final, and add hibernate-entitymanager
5. Run "mvn clean test" again
6. No test error
**Environment (please complete the following information):**
-
* Output of `uname -a` or `ver`:
MSYS_NT-10.0 NANB7NLNVP2 2.10.0(0.325/5/3) 2018-06-13 23:34 x86_64 Msys
- * Build tool (ie. output of `mvnw --version` or `gradlew --version`):
Maven home: C:\ \ eclipse\ \ tools\ \ apache-maven\ \ bin\ \..
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: C:\ \ Program Files\ \ Java\ \ jdk1.8.0_181\ \ jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
( https://hibernate.atlassian.net/browse/HHH-14060#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-14060#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100128- sha1:e736ab1 )
5 years, 6 months