diff --git a/modules/typed-ids-hibernate-63/src/main/java/org/framefork/typedIds/bigint/hibernate/id/ObjectBigIntIdIdentityGenerator.java b/modules/typed-ids-hibernate-63/src/main/java/org/framefork/typedIds/bigint/hibernate/id/ObjectBigIntIdIdentityGenerator.java index 16c45fd..b713104 100644 --- a/modules/typed-ids-hibernate-63/src/main/java/org/framefork/typedIds/bigint/hibernate/id/ObjectBigIntIdIdentityGenerator.java +++ b/modules/typed-ids-hibernate-63/src/main/java/org/framefork/typedIds/bigint/hibernate/id/ObjectBigIntIdIdentityGenerator.java @@ -1,5 +1,6 @@ package org.framefork.typedIds.bigint.hibernate.id; +import org.framefork.typedIds.bigint.ObjectBigIntId; import org.framefork.typedIds.bigint.hibernate.ObjectBigIntIdType; import org.framefork.typedIds.common.ReflectionHacks; import org.hibernate.HibernateException; @@ -7,6 +8,7 @@ import org.hibernate.id.PostInsertIdentityPersister; import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate; import org.hibernate.service.ServiceRegistry; +import org.hibernate.type.BasicType; import org.hibernate.type.CustomType; import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.spi.JavaTypeBasicAdaptor; @@ -52,7 +54,14 @@ private ObjectBigIntIdType toObjectBigIntIdType(final Type type) } } - throw new HibernateException("The given type is expected to be a CustomType wrapper over a %s, but was '%s' instead".formatted(ObjectBigIntIdType.class.getSimpleName(), type)); + if (type instanceof BasicType basicType) { + var javaTypeClass = basicType.getExpressibleJavaType().getJavaTypeClass(); + if (ObjectBigIntId.class.isAssignableFrom(javaTypeClass)) { + return new ObjectBigIntIdType(javaTypeClass, basicType.getJdbcType()); + } + } + + throw new HibernateException("The given type is expected to be ObjectBigIntIdType or a wrapper containing an ObjectBigIntId subclass, but was '%s' instead".formatted(type)); } private JdbcType toJdbcType(final ObjectBigIntIdType objectBigIntIdType) diff --git a/modules/typed-ids-hibernate-63/src/main/java/org/framefork/typedIds/bigint/hibernate/id/ObjectBigIntIdSequenceStyleGenerator.java b/modules/typed-ids-hibernate-63/src/main/java/org/framefork/typedIds/bigint/hibernate/id/ObjectBigIntIdSequenceStyleGenerator.java index b713e4a..faf6b58 100644 --- a/modules/typed-ids-hibernate-63/src/main/java/org/framefork/typedIds/bigint/hibernate/id/ObjectBigIntIdSequenceStyleGenerator.java +++ b/modules/typed-ids-hibernate-63/src/main/java/org/framefork/typedIds/bigint/hibernate/id/ObjectBigIntIdSequenceStyleGenerator.java @@ -1,10 +1,12 @@ package org.framefork.typedIds.bigint.hibernate.id; +import org.framefork.typedIds.bigint.ObjectBigIntId; import org.framefork.typedIds.bigint.hibernate.ObjectBigIntIdType; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.service.ServiceRegistry; +import org.hibernate.type.BasicType; import org.hibernate.type.CustomType; import org.hibernate.type.Type; import org.hibernate.type.descriptor.java.spi.JavaTypeBasicAdaptor; @@ -55,7 +57,14 @@ private ObjectBigIntIdType toObjectBigIntIdType(final Type type) } } - throw new HibernateException("The given type is expected to be a CustomType wrapper over a %s, but was '%s' instead".formatted(ObjectBigIntIdType.class.getSimpleName(), type)); + if (type instanceof BasicType basicType) { + var javaTypeClass = basicType.getExpressibleJavaType().getJavaTypeClass(); + if (ObjectBigIntId.class.isAssignableFrom(javaTypeClass)) { + return new ObjectBigIntIdType(javaTypeClass, basicType.getJdbcType()); + } + } + + throw new HibernateException("The given type is expected to be ObjectBigIntIdType or a wrapper containing an ObjectBigIntId subclass, but was '%s' instead".formatted(type)); } private JdbcType toJdbcType(final ObjectBigIntIdType objectBigIntIdType)