JPA & JTA - Error during managed flush [Session/EntityManager is closed] on flush-time cascades

Description

While merging an entity with deleting a cascaded reference i get this exception:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 DEBUG [org.springframework.orm.jpa.EntityManagerFactoryUtils] (default task-37) Closing JPA EntityManager DEBUG [org.springframework.transaction.jta.JtaTransactionManager] (default task-37) Initiating transaction commit DEBUG [org.hibernate.event.internal.AbstractFlushingEventListener] (default task-37) Processing flush-time cascades ERROR [org.hibernate.internal.ExceptionMapperStandardImpl] (default task-37) HHH000346: Error during managed flush [Session/EntityManager is closed] WARN [com.arjuna.ats.arjuna] (default task-37) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffffc0a83801:22518f31:58344134:7036, org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization@25166cc5 >: java.lang.IllegalStateException: Session/EntityManager is closed at org.hibernate.internal.AbstractSharedSessionContract.checkOpen(AbstractSharedSessionContract.java:332) at org.hibernate.engine.spi.SharedSessionContractImplementor.checkOpen(SharedSessionContractImplementor.java:126) at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:991) at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:924) at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:241) at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:104) at org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:150) at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:141) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:74) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:38) at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1406) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:476) at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3165) at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2379)

I simple try to update a existing entity and a nested association is removed, this should trigger an orphan removal.

1 2 3 4 @Transactional(readOnly = false) public Customer updateCustomer(final Customer customer) { return this.customerRepository.save(customer); }

and the repository is a Spring Data JPA repository.

Environment

None

Status

Assignee

Andrea Boriero

Reporter

Julian Hochstetter

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.4

Priority

Major