entityManagerRegistry.removeEntityManagers((String) beanContext.getDeploymentID(), instance.primaryKey);
}
private void registerSessionSynchronization(Instance instance, ThreadContext callContext) {
TransactionPolicy txPolicy = callContext.getTransactionPolicy();
if (txPolicy == null) {
throw new IllegalStateException("ThreadContext does not contain a TransactionEnvironment");
}
SessionSynchronizationCoordinator coordinator = (SessionSynchronizationCoordinator) txPolicy.getResource(SessionSynchronizationCoordinator.class);
if (coordinator == null) {
coordinator = new SessionSynchronizationCoordinator(txPolicy);
txPolicy.registerSynchronization(coordinator);
txPolicy.putResource(SessionSynchronizationCoordinator.class, coordinator);
}
// SessionSynchronization are only enabled for beans after CREATE that are not bean-managed and implement the SessionSynchronization interface
boolean synchronize = callContext.getCurrentOperation() != Operation.CREATE &&
callContext.getBeanContext().isSessionSynchronized() &&
txPolicy.isTransactionActive();
coordinator.registerSessionSynchronization(instance, callContext.getBeanContext(), callContext.getPrimaryKey(), synchronize);
}