When the log level for hibernate is set to DEBUG (or FINE in Wildfly), hibernate may exhibit ConcurrentModificationExceptions when trying to print entities in EntityPrinter.toString(EntityPrinter.java:104).
In order to exhibit this behavior certain requirements must be fulfilld (see test case for example):
Log Level set to DEBUG or finer
hibernate property: hibernate.jpa.compliance.proxy=true
Lazy Loading must be enabled and the child class must be proxied
Must load at least two parent entities
The process of getting the Exception is roughly as follows:
Store 1 child entity and 2 parent entities referencing the child entity.
Get a clean slate by clearing the PersistenceContext
Load the 2 Parent Entities with the child entity being lazily loaded as a proxy
commit or flush the transaction
While printing the first parent entity, the child entity will be initialized and added to the "EntitiesByKey" Map of the Persistence Context. Then iteration will then proceed to the next parent entity and notice that the HashMap has been modified and throw the ConcurrentModificationException.
See test case for more information.
Probably a duplicate of HHH-2218, just including a test case.
Hibernate: 5.3.6 (production), 5.4.0 (Test Case)
OS: Windows 10
JDK: AdoptOpenJDK 1.8.0_202-b08
DB: Oracle (production) and h2 (Test)