@@ -235,9 +235,9 @@ public EntityMetamodel(
235235 boolean foundUpdateableNaturalIdProperty = false ;
236236 BeforeExecutionGenerator tempVersionGenerator = null ;
237237
238- List <Property > props = persistentClass .getPropertyClosure ();
238+ final List <Property > props = persistentClass .getPropertyClosure ();
239239 for ( int i =0 ; i <props .size (); i ++ ) {
240- Property property = props .get (i );
240+ final Property property = props .get (i );
241241 final NonIdentifierAttribute attribute ;
242242 if ( property == persistentClass .getVersion () ) {
243243 tempVersionProperty = i ;
@@ -310,9 +310,11 @@ public EntityMetamodel(
310310 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311311
312312 // generated value strategies ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313+
313314 final Generator generator = buildGenerator ( name , property , creationContext );
314315 if ( generator != null ) {
315- if ( i == tempVersionProperty && !generator .generatedOnExecution () ) {
316+ final boolean generatedOnExecution = generator .generatedOnExecution ();
317+ if ( i == tempVersionProperty && !generatedOnExecution ) {
316318 // when we have an in-memory generator for the version, we
317319 // want to plug it in to the older infrastructure specific
318320 // to version generation, instead of treating it like a
@@ -321,33 +323,33 @@ public EntityMetamodel(
321323 }
322324 else {
323325 generators [i ] = generator ;
324- if ( ! generator .allowMutation () ) {
325- propertyInsertability [ i ] = false ;
326- propertyUpdateability [i ] = false ;
326+ final boolean allowMutation = generator .allowMutation ();
327+ if ( ! allowMutation ) {
328+ propertyCheckability [i ] = false ;
327329 }
328330 if ( generator .generatesOnInsert () ) {
329- propertyInsertability [i ] = !generatedWithNoParameter ( generator );
330- if ( generator .generatedOnExecution () ) {
331- foundPostInsertGeneratedValues = true ;
332- if ( generator instanceof BeforeExecutionGenerator ) {
333- foundPreInsertGeneratedValues = true ;
334- }
335- }
336- else {
337- foundPreInsertGeneratedValues = true ;
331+ if ( generatedOnExecution ) {
332+ propertyInsertability [i ] = writePropertyValue ( (OnExecutionGenerator ) generator );
338333 }
334+ foundPostInsertGeneratedValues = foundPostInsertGeneratedValues
335+ || generator instanceof OnExecutionGenerator ;
336+ foundPreInsertGeneratedValues = foundPreInsertGeneratedValues
337+ || generator instanceof BeforeExecutionGenerator ;
338+ }
339+ else if ( !allowMutation ) {
340+ propertyInsertability [i ] = false ;
339341 }
340342 if ( generator .generatesOnUpdate () ) {
341- propertyUpdateability [i ] = !generatedWithNoParameter ( generator );
342- if ( generator .generatedOnExecution () ) {
343- foundPostUpdateGeneratedValues = true ;
344- if ( generator instanceof BeforeExecutionGenerator ) {
345- foundPreUpdateGeneratedValues = true ;
346- }
347- }
348- else {
349- foundPreUpdateGeneratedValues = true ;
343+ if ( generatedOnExecution ) {
344+ propertyUpdateability [i ] = writePropertyValue ( (OnExecutionGenerator ) generator );
350345 }
346+ foundPostUpdateGeneratedValues = foundPostUpdateGeneratedValues
347+ || generator instanceof OnExecutionGenerator ;
348+ foundPreUpdateGeneratedValues = foundPreUpdateGeneratedValues
349+ || generator instanceof BeforeExecutionGenerator ;
350+ }
351+ else if ( !allowMutation ) {
352+ propertyUpdateability [i ] = false ;
351353 }
352354 }
353355 }
@@ -472,6 +474,15 @@ && isAbstractClass( persistentClass.getMappedClass() ) ) {
472474// entityNameByInheritanceClassMap = toSmallMap( entityNameByInheritanceClassMapLocal );
473475 }
474476
477+ private static boolean writePropertyValue (OnExecutionGenerator generator ) {
478+ final boolean writePropertyValue = generator .writePropertyValue ();
479+ // TODO: move this validation somewhere else!
480+ // if ( !writePropertyValue && generator instanceof BeforeExecutionGenerator ) {
481+ // throw new HibernateException( "BeforeExecutionGenerator returned false from OnExecutionGenerator.writePropertyValue()" );
482+ // }
483+ return writePropertyValue ;
484+ }
485+
475486 private Generator buildIdGenerator (PersistentClass persistentClass , RuntimeModelCreationContext creationContext ) {
476487 final Generator existing = creationContext .getGenerators ().get ( rootName );
477488 if ( existing != null ) {
@@ -513,11 +524,6 @@ private String propertyName(Property property) {
513524 return getName () + "." + property .getName ();
514525 }
515526
516- private static boolean generatedWithNoParameter (Generator generator ) {
517- return generator .generatedOnExecution ()
518- && !((OnExecutionGenerator ) generator ).writePropertyValue ();
519- }
520-
521527 private static Generator buildGenerator (
522528 final String entityName ,
523529 final Property mappingProperty ,
0 commit comments