Envers tries to use relationship's entity as value for column instead of numeric identifier (cast class exception happens) for LAZY @ManyToOne

Description

I have an entity mapped as:

ID of Address.Version is composite of Address entity + a numeric version number (not related to `@javax.persistence.Version`).
ID of Address is numeric ID.
ID of Shipment numeric ID.

and when an update transaction is about to commit, I get:

I cannot be 100% sure but I think this started to happen when we moved to both origin and destination addresses being `optional=true`

Environment

JDK 11, Mac OS X

Activity

Show:
William Webb
January 8, 2020, 6:43 PM
Edited

I’m experiencing an eerily similar issue with both 5.3.9 and 5.3.13, which was /not/ experienced with 5.1.

Hibernate itself has no issue inserting new rows:

 

Now, Envers enters the scene as it attempts to audit. Revision is created:

 

Then... oddity when trying to create an audit entry for the above entity change (new/insert):

 

 

Updates to entities do not have this issue:

 

We’re not experiencing this on all audited entities.

For the record, the annotations are as follows (abbreviated):

 

 

(sorry for the long comment)

Francisco Alejandro Lozano López
January 10, 2020, 6:46 AM

Well! I’m “glad” to see I’m not the only one having this kind of issue, if that serves to raise more attention on the issue…

Chris Cranford
January 13, 2020, 11:06 PM
Edited

A quick update, I believe I have a fix in the works for this. The reason I believed this failed is because when mapped as LAZY, the ToOneIdMapper wasn't taking into account that the associated entity object needed to be resolved from the proxy to its non-proxy counter-part. I need to run some tests and validate this doesn't break anything and if that's the case, you should expect to see a PR shortly.

Thanks guys for the wonderful feedback and tests as this helped diagnose the problem relatively easily.

Chris Cranford
January 13, 2020, 11:31 PM
Edited

or ,

Can either you give the PR changes in https://github.com/hibernate/hibernate-orm/pull/3170 a try and let me know if that truly solves your issues? The test case provided by Francisco passes, but would like to be sure we've covered all bases.

Francisco Alejandro Lozano López
February 10, 2020, 11:55 AM

I didn’t see the notifications about the issue, I’m sorry. I checked my code and works well with latest changes, so thank you for fixing.

Assignee

Chris Cranford

Reporter

Francisco Alejandro Lozano López

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Critical
Configure