diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java index ad8f247142..885ab6fd55 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/PropertyBinder.java @@ -448,12 +448,15 @@ public class PropertyBinder { return creator; } - private static void checkGeneratorType(Class generatorClass) { + private static void checkGeneratorClass(Class generatorClass) { if ( !InMemoryGenerator.class.isAssignableFrom( generatorClass ) && !InDatabaseGenerator.class.isAssignableFrom( generatorClass ) ) { throw new MappingException("Generator class '" + generatorClass.getName() + "' must implement either 'InMemoryGenerator' or 'InDatabaseGenerator'"); } + } + + private static void checkGeneratorInterfaces(Class generatorClass) { // we don't yet support the additional "fancy" operations of // IdentifierGenerator with regular generators, though this // would be extremely easy to add if anyone asks for it @@ -480,7 +483,9 @@ public class PropertyBinder { if ( generatorAnnotation == null ) { return null; } - checkGeneratorType( generatorAnnotation.generatedBy() ); + final Class generatorClass = generatorAnnotation.generatedBy(); + checkGeneratorClass( generatorClass ); + checkGeneratorInterfaces( generatorClass ); return creationContext -> { final Generator generator = instantiateGenerator( @@ -489,7 +494,7 @@ public class PropertyBinder { annotationType, creationContext, GeneratorCreationContext.class, - generatorAnnotation.generatedBy() + generatorClass ); callInitialize( annotation, member, creationContext, generator ); checkVersionGenerationAlways( property, generator ); @@ -503,6 +508,8 @@ public class PropertyBinder { final IdGeneratorType idGeneratorType = annotationType.getAnnotation( IdGeneratorType.class ); assert idGeneratorType != null; return creationContext -> { + final Class generatorClass = idGeneratorType.value(); + checkGeneratorClass( generatorClass ); final Generator generator = instantiateGenerator( annotation, @@ -510,7 +517,7 @@ public class PropertyBinder { annotationType, creationContext, CustomIdGeneratorCreationContext.class, - idGeneratorType.value() + generatorClass ); callInitialize( annotation, member, creationContext, generator ); checkIdGeneratorTiming( annotationType, generator );