Scott has verified that the failure he is seeing involves 2 synchronizations. 
The first is from EntityManagerImpl and the second is HSearch.

The problem is that the EntityManagerImpl (anonymous) 
Synchronization.afterCompletion() closes the session, which in turn, calls 
TransactionCoordinatorImpl.close() which calls reset(), which clears the 
synchronizations from the registry. After that finishes, 
SynchronizationRegistryImpl.notifySynchronizationsAfterTransactionCompletion() 
attempts to execute HSearch afterCompletion() synchronization, but the registry 
has already been cleared, resulting in the ConcurrentModificationException.

I initially thought a possible fix would be to defer calling 
TransactionCoordinatorImpl.reset() if the afterCompletion() synchronizations 
are being executed. Doing this would be fairly straightforward. 

The problem is that, since the EntityManager afterCompletion() synchronization 
is executed first, the session would be closed before the HSearch 
afterCompletion() synchronization is executed. I mentioned this to Sanne and he 
said that the HSearch afterCompletion() synchronization might need access to 
the persistence context to, for example, initialize a collection, or to get 
entity state. Obviously it can't if the session is already closed.

Is there a reason why the EntityManager synchronization is registered before 
the HSearch synchronization?

Is there a way to always make the "session-closing" synchronization last?

Steve, do you see a better way around this?

Thanks,
Gail
_______________________________________________
hibernate-dev mailing list
hibernate-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hibernate-dev

Reply via email to