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.
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).
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.
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”.
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.
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.