Component.sortProperties() reorders Envers originalId key, breaking joined audit-table FK/joins for JOINED inheritance

When Envers is used with a JOINED inheritance hierarchy, it can reorder the audit table composite key columns, and causes joined audit-table reads to fail. Created an issue in tracker Jira

Thanks for the report. Can you please also try with the latest Hibernate ORM version and ideally create a reproducer based on our test case template?

Hi @beikov , Thanks for the response

I retested this with newer Hibernate ORM versions and can still reproduce it.

Tested versions:

  • 6.6.49.Final
  • 7.3.1.Final

The issue still occurs on both versions.

I also created a standalone reproducer based on the JPA test-case template, using H2: reproducer

Observed failure:

Unexpected result size. SQL: [select pav1_0.PTY_ID,pav1_0.REV_ID,pav1_1.FULL_NAME,pav1_0.FIRST_NAME,pav1_0.LAST_NAME from PERSON_AUD pav1_0 join PARTY_AUD pav1_1 on pav1_0.PTY_ID=pav1_1.REV_ID and pav1_0.REV_ID=pav1_1.PTY_ID order by pav1_1.REV_ID]

So the standalone reproducer shows the same problem:

  • JOINED inheritance
  • Envers audit tables
  • read-only audit view entities with inherited @IdClass
  • generated join between PERSON_AUD and PARTY_AUD uses swapped columns

Expected join:

… on pav1_0.PTY_ID=pav1_1.PTY_ID and pav1_0.REV_ID=pav1_1.REV_ID

Actual join:

… on pav1_0.PTY_ID=pav1_1.REV_ID and pav1_0.REV_ID=pav1_1.PTY_ID

Awesome, please create a Jira ticket for this and post the link here.

Bug was already created for this. HHH-20357
Let me know if I need to create another one @beikov
Thanks!

I see that you also added a reproducer on the Jira ticket now. Thanks for that. We’ll try to look into it as soon as possible.