fix: support Java 25 type wrapping in Hibernate 6.6 #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Java 25 compatibility issue in
typed-ids-hibernate-63library where Hibernate 6.6 throwsHibernateExceptionwhen using custom ID generators withObjectBigIntIdtypes.Problem
On Java 25, Hibernate 6.6 changed how it wraps custom types, causing ID generators to fail with:
org.hibernate.HibernateException: The given type is expected to be a CustomType wrapper over a ObjectBigIntIdType, but was 'basicType@146(cz.rohlik.referrer.persistence.ReferrerUserId,-3)' instead
Root Cause
Different type wrapping behavior between Java versions:
Java 21:
CustomType wrapper
└─> ObjectBigIntIdType (recognized custom UserType)
Java 25:
BasicTypeImpl wrapper
└─> SerializableJavaType (treats ObjectBigIntId as generic Serializable)
└─> ReferrerUserId.class (concrete ID class exteding ObjectBigIntId)
Hibernate 6.6 on Java 25 no longer recognizes the registered
ObjectBigIntIdTypeand falls back to treatingObjectBigIntIdsubclasses as genericSerializabletypes wrapped inBasicTypeImpl.Solution
Updated both ID generators to handle both wrapping strategies:
Changes
Modified Files:
ObjectBigIntIdSequenceStyleGenerator.javaObjectBigIntIdIdentityGenerator.javaKey Changes:
BasicTypewrapper detection for Java 25 compatibilitySerializableJavaTypewrapperObjectBigIntIdTypewith the extracted class and JDBC typeCustomTypewrapperCode Example