Skip to content

Fix Hibernate 7.4 dropping primary key on order_type_class_map join table#6139

Open
dkayiwa wants to merge 1 commit into
masterfrom
fix/hibernate-7.4-order-type-join-table-pk
Open

Fix Hibernate 7.4 dropping primary key on order_type_class_map join table#6139
dkayiwa wants to merge 1 commit into
masterfrom
fix/hibernate-7.4-order-type-join-table-pk

Conversation

@dkayiwa
Copy link
Copy Markdown
Member

@dkayiwa dkayiwa commented May 28, 2026

Summary

Prepares the codebase for the Hibernate 7.4 upgrade (#6130). On Hibernate 7.4, the integration-test job fails with org.dbunit.dataset.NoPrimaryKeyException: ORDER_TYPE_CLASS_MAP (97 errors across many ITs).

Root cause

The test harness builds the in-memory H2 schema from Hibernate's hbm2ddl, and dbUnit's REFRESH operation needs a primary key to update existing rows. In Hibernate 7.4, when a @JoinTable's explicit @UniqueConstraint covers exactly the columns that would form the join table's composite primary key, Hibernate emits the unique constraint instead of the primary key.

OrderType.conceptClasses was the only @ManyToMany Set declaring such a redundant @UniqueConstraint, so its order_type_class_map join table lost its primary key (user_role and location_tag_map, which have no explicit unique constraint, kept theirs).

Fix

Remove the redundant @UniqueConstraint. The two FK columns are the natural key of a Set join table, so hbm2ddl generates the composite primary key automatically again — matching the production schema, which already defines that PK via Liquibase (liquibase-update-to-latest-2.0.x.xml). The annotation's uniqueConstraints only ever affected hbm2ddl-generated DDL, so production is unaffected and the change is harmless on the current Hibernate 7.3.6 too.

Testing

Locally bumped Hibernate to 7.4.0 and reran the affected tests:

  • Before: ConceptIT, ModuleUtilIT, SchedulerServiceIT, S3StorageServiceIT, Database1_9_7UpgradeIT → 97 errors.
  • After: all green, including ValidateHibernateMappingsDatabaseIT (mapping-vs-schema validation) and the 238 OrderServiceTest / OrderTypeTest cases.

Once this merges, Dependabot PR #6130 will rebase and pass.

🤖 Generated with Claude Code

@dkayiwa dkayiwa force-pushed the fix/hibernate-7.4-order-type-join-table-pk branch from d3b7002 to 8486025 Compare May 28, 2026 00:47
…able

Hibernate 7.4 emits a unique constraint instead of a composite primary
key when a @jointable's explicit @UniqueConstraint covers exactly the
columns that would form the join table's primary key. OrderType was the
only @manytomany Set declaring such a redundant @UniqueConstraint, so its
order_type_class_map join table lost its primary key under hbm2ddl. This
broke the integration tests, whose dbUnit REFRESH operation needs a
primary key to update existing rows (NoPrimaryKeyException).

Remove the redundant @UniqueConstraint: the two FK columns are the natural
key of a Set join table, so hbm2ddl generates the composite primary key
again, matching the production schema that already defines it via
Liquibase. The annotation only affected hbm2ddl-generated DDL, so
production is unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dkayiwa dkayiwa force-pushed the fix/hibernate-7.4-order-type-join-table-pk branch from 8486025 to 340ebc8 Compare May 28, 2026 00:51
@sonarqubecloud
Copy link
Copy Markdown

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.06%. Comparing base (9282315) to head (340ebc8).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6139      +/-   ##
============================================
+ Coverage     59.04%   59.06%   +0.01%     
- Complexity     9239     9242       +3     
============================================
  Files           693      693              
  Lines         37257    37257              
  Branches       5485     5485              
============================================
+ Hits          21998    22004       +6     
+ Misses        13287    13285       -2     
+ Partials       1972     1968       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants