diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index bc3f47ccae..7aa2b55bbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -2523,42 +2523,7 @@ public class ModelBinder { // NOTE : Property#is refers to whether a property is lazy via bytecode enhancement (not proxies) property.setLazy( singularAttributeSource.isBytecodeLazy() ); - final GenerationTiming timing = singularAttributeSource.getGenerationTiming(); - if ( timing != null ) { - if ( (timing == GenerationTiming.INSERT || timing == GenerationTiming.UPDATE) - && property.getValue() instanceof SimpleValue - && ((SimpleValue) property.getValue()).isVersion() ) { - // this is enforced by DTD, but just make sure - throw new MappingException( - "'generated' attribute cannot be 'insert' or 'update' for version/timestamp property", - mappingDocument.getOrigin() - ); - } - if ( timing != GenerationTiming.NEVER ) { - property.setValueGeneratorCreator( context -> new GeneratedGeneration( timing.getEquivalent() ) ); - - // generated properties can *never* be insertable... - if ( property.isInsertable() && timing.includesInsert() ) { - log.debugf( - "Property [%s] specified %s generation, setting insertable to false : %s", - propertySource.getName(), - timing.name(), - mappingDocument.getOrigin() - ); - property.setInsertable( false ); - } - - // properties generated on update can never be updatable... - if ( property.isUpdateable() && timing.includesUpdate() ) { - log.debugf( - "Property [%s] specified ALWAYS generation, setting updateable to false : %s", - propertySource.getName(), - mappingDocument.getOrigin() - ); - property.setUpdateable( false ); - } - } - } + handleGenerationTiming( mappingDocument, propertySource, property, singularAttributeSource.getGenerationTiming() ); } property.setMetaAttributes( propertySource.getToolingHintContext().getMetaAttributeMap() ); @@ -2568,6 +2533,48 @@ public class ModelBinder { } } + private static void handleGenerationTiming( + MappingDocument mappingDocument, + AttributeSource propertySource, + Property property, + GenerationTiming timing) { + if ( timing != null ) { + if ( (timing == GenerationTiming.INSERT || timing == GenerationTiming.UPDATE) + && property.getValue() instanceof SimpleValue + && ((SimpleValue) property.getValue()).isVersion() ) { + // this is enforced by DTD, but just make sure + throw new MappingException( + "'generated' attribute cannot be 'insert' or 'update' for version/timestamp property", + mappingDocument.getOrigin() + ); + } + if ( timing != GenerationTiming.NEVER ) { + property.setValueGeneratorCreator(context -> new GeneratedGeneration( timing.getEquivalent() ) ); + + // generated properties can *never* be insertable... + if ( property.isInsertable() && timing.includesInsert() ) { + log.debugf( + "Property [%s] specified %s generation, setting insertable to false : %s", + propertySource.getName(), + timing.name(), + mappingDocument.getOrigin() + ); + property.setInsertable( false ); + } + + // properties generated on update can never be updatable... + if ( property.isUpdateable() && timing.includesUpdate() ) { + log.debugf( + "Property [%s] specified ALWAYS generation, setting updateable to false : %s", + propertySource.getName(), + mappingDocument.getOrigin() + ); + property.setUpdateable( false ); + } + } + } + } + private void bindComponent( MappingDocument sourceDocument, EmbeddableSource embeddableSource,