As mentioned in this [Pull Request|https://github.com/hibernate/hibernate-orm/pull/2126]:
{noformat} I don't think it's enough for initializeProxyWhenAccessingIdentifier to be a field.
Here is a scenario where there could be problems:
the object is constructed, using a SessionFactory with hibernate.jpa.compliance.proxy=false configured; the object is detached and session is set to null; the object is attached to a Session for a different SessionFactory with hibernate.jpa.compliance.proxy=true configured; the application calls getIdentifier(), which returns the ID without initializing the entity. Since hibernate.jpa.compliance.proxy=true is configured in the new SessionFactory, the entity should have been initialized before returning the ID.
I think that the sessionFactoryUuid should also be assigned, and the SessionFactory should be checked in getIdentifier(), similar to what is done for allowLoadOutsideTransaction.
IMO, when the object gets reattached to a Session, sessionFactoryUuid should be updated to the UUID for Session's SessionFactory. {noformat}
We should consider this usse use case as well. |
|