@Audited @ElementCollection field that is joined using more than one @JoinColumn leads to NPE when value is changed

Description

What I do:
Configure entity like this

The idea is to have a table foos_bars_mapping which has three columns foo_id, bar_id, baz_id and a composite foreign key of foo_id+baz_id referring to foo table (but having or not having this FK does not affect the test).
Persist an entity.
Change the value of barIds.
Persist again.
What I expect:
All is fine, Envers processes this change fine, creates some rows in foos_bars_mapping_aud
What I get instead:
Envers fails with NPE trying to find a getter for some property that does not exist and is some detail of implementation of this two-columns mapping.

Reproducer can be found here (I'm reproducing this on 5.2.8, but observe the same error on 5.4.x).

Notes:
If mapping is done through one column and not two, all works fine.
If I mark this barIds field as @NotAudited, NPE does not happen.

Thanks!

Environment

None

Activity

Show:
Mikhail Gromov
6 days ago
Edited

Here is a naive PR that does the trick, but in a weird way: . But probably you will find that this solution is acceptable with some TODO item like “fix properly, drag isSynthetic correctly”.

Mikhail Gromov
5 days ago

This reminds me - there was the same NPE and very similar cause: some SyntheticProperty created to make some join work. And the fix was to skip SyntheticProperty if it is an alternate unique key:

Can you maybe suggest me a way to make Hibernate think that this composite property I generated is an alternate unique key? I have already tried to put @NaturalId on both fields that participate in this join with no luck. Apparently, @OneToMany and @ElementCollection have more differences than it seemed to me at first.

Mikhail Gromov
3 days ago

Hm, actually that place in AuditMetadataReader looks like a better place for my fix than where I have originally put it. Updated the PR accordingly.

Assignee

Chris Cranford

Reporter

Mikhail Gromov

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure