Chris Cranford (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HHH-15445 (
https://hibernate.atlassian.net/browse/HHH-15445?atlOrigin=eyJpIjoiMjhiZG...
)
Re: Envers inserts erroneous audit entries for many-to-many relation if using
`global_with_modified_flag` (
https://hibernate.atlassian.net/browse/HHH-15445?atlOrigin=eyJpIjoiMjhiZG...
)
As explained on Zulip, the issue in this situation is the use of getReference() versus
find().
In order for Envers to perform proper diff analysis on entity state, the entity must be
loaded fully into the PersistenceContext. When using getReference() , the entity’s full
state isn’t loaded by ORM and therefore only the primary key fields are available. Envers
also does not lazily load this state because this can create other cascading concerns
during the listener invocation. So we ultimately rely on the user to guarantee the
entity’s state is loaded so the right audit state gets persisted.
You can workaround and avoid this by using EntityManager#find() rather than
EntityManager#getReference().
(
https://hibernate.atlassian.net/browse/HHH-15445#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15445#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100204- sha1:2e7ea99 )