setting hibernate.jpa.compliance.proxy=true and org.hibernate debug level to DEBUG breaks hibernate

Description

When the org.hibernate debug level is set to at least DEBUG, and
hibernate.jpa.compliance.proxy property is set to true hibernate throws an exception on transaction commit on rather simple entity graphs. (Even when the transaction does not modify the state)

When setting only the debug level or the property, hibernate works correctly.

The Excpetion thrown is either a ConcurrentModificationExcption in EntityPrinter.java,

or an

org.hibernate.HibernateException: HHH000479: Collection [org.hibernate.bugs.MvnoOpcio.mvnoBillingAgreementekDefaultOpcioja] was not processed by flush(). This is likely due to unsafe use of the session (e.g. used in multiple threads concurrently, updates during entity lifecycle hooks).

Depending on the environment, the PersistenceContext complexity, and whether the Iterator in EntityPrinter can detect the change in the underlying Collection.

This seems to be related to HHH-2218, as the EntityPrinter.java class seems to trigger an Entity load ( as can be seen in the attached log fragment)

Environment

Hibernate 5.3.7 in Wildfly 15.0.1.Final
java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
CentOS Linux release 7.6.1810 (Core)

DB independent (triggers both with mysql and H2)

Status

Assignee

Gail Badner

Reporter

Tóth István

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.2.11

Components

Affects versions

5.3.7
5.4.1

Priority

Minor