|
|
@ -266,6 +266,7 @@ public abstract class EntityManagerFactoryUtils { |
|
|
|
em = (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); |
|
|
|
em = (!CollectionUtils.isEmpty(properties) ? emf.createEntityManager(properties) : emf.createEntityManager()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// Use same EntityManager for further JPA operations within the transaction.
|
|
|
|
// Use same EntityManager for further JPA operations within the transaction.
|
|
|
|
// Thread-bound object will get removed by synchronization at transaction completion.
|
|
|
|
// Thread-bound object will get removed by synchronization at transaction completion.
|
|
|
|
emHolder = new EntityManagerHolder(em); |
|
|
|
emHolder = new EntityManagerHolder(em); |
|
|
@ -281,6 +282,12 @@ public abstract class EntityManagerFactoryUtils { |
|
|
|
new TransactionScopedEntityManagerSynchronization(emHolder, emf)); |
|
|
|
new TransactionScopedEntityManagerSynchronization(emHolder, emf)); |
|
|
|
} |
|
|
|
} |
|
|
|
TransactionSynchronizationManager.bindResource(emf, emHolder); |
|
|
|
TransactionSynchronizationManager.bindResource(emf, emHolder); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (RuntimeException ex) { |
|
|
|
|
|
|
|
// Unexpected exception from external delegation call -> close EntityManager and rethrow.
|
|
|
|
|
|
|
|
closeEntityManager(em); |
|
|
|
|
|
|
|
throw ex; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return em; |
|
|
|
return em; |
|
|
|
} |
|
|
|
} |
|
|
|