Skip to content

Commit 31f43d3

Browse files
committed
HHH-18815 WTF is going on here??
Signed-off-by: Gavin King <[email protected]>
1 parent a259dd3 commit 31f43d3

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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,36 +323,50 @@ 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 ) {
327328
propertyCheckability[i] = false;
328329
}
329-
final boolean noParameter = generatedWithNoParameter( generator );
330330
if ( generator.generatesOnInsert() ) {
331-
propertyInsertability[i] = !noParameter;
332-
if ( generator.generatedOnExecution() ) {
333-
foundPostInsertGeneratedValues = true;
334-
if ( generator instanceof BeforeExecutionGenerator ) {
335-
foundPreInsertGeneratedValues = true;
331+
if ( generatedOnExecution ) {
332+
final OnExecutionGenerator onExecutionGenerator = (OnExecutionGenerator) generator;
333+
final boolean writePropertyValue = onExecutionGenerator.writePropertyValue();
334+
propertyInsertability[i] = writePropertyValue;
335+
// TODO: move this validation somewhere else!
336+
if ( !writePropertyValue && generator instanceof BeforeExecutionGenerator ) {
337+
throw new HibernateException( "BeforeExecutionGenerator returned false from OnExecutionGenerator.writePropertyValue()" );
336338
}
337339
}
338-
else {
340+
if ( generator instanceof OnExecutionGenerator ) {
341+
foundPostInsertGeneratedValues = true;
342+
}
343+
if ( generator instanceof BeforeExecutionGenerator ) {
339344
foundPreInsertGeneratedValues = true;
340345
}
341346
}
347+
else if ( !allowMutation ) {
348+
propertyInsertability[i] = false;
349+
}
342350
if ( generator.generatesOnUpdate() ) {
343-
propertyUpdateability[i] = !noParameter;
344-
if ( generator.generatedOnExecution() ) {
345-
foundPostUpdateGeneratedValues = true;
346-
if ( generator instanceof BeforeExecutionGenerator ) {
347-
foundPreUpdateGeneratedValues = true;
351+
if ( generatedOnExecution ) {
352+
final OnExecutionGenerator onExecutionGenerator = (OnExecutionGenerator) generator;
353+
final boolean writePropertyValue = onExecutionGenerator.writePropertyValue();
354+
propertyUpdateability[i] = writePropertyValue;
355+
// TODO: move this validation somewhere else!
356+
if ( !writePropertyValue && generator instanceof BeforeExecutionGenerator ) {
357+
throw new HibernateException( "BeforeExecutionGenerator returned false from OnExecutionGenerator.writePropertyValue()" );
348358
}
349359
}
350-
else {
360+
if ( generator instanceof OnExecutionGenerator ) {
361+
foundPostUpdateGeneratedValues = true;
362+
}
363+
if ( generator instanceof BeforeExecutionGenerator ) {
351364
foundPreUpdateGeneratedValues = true;
352365
}
353366
}
367+
else if ( !allowMutation ) {
368+
propertyUpdateability[i] = false;
369+
}
354370
}
355371
}
356372

@@ -515,11 +531,6 @@ private String propertyName(Property property) {
515531
return getName() + "." + property.getName();
516532
}
517533

518-
private static boolean generatedWithNoParameter(Generator generator) {
519-
return generator.generatedOnExecution()
520-
&& !((OnExecutionGenerator) generator).writePropertyValue();
521-
}
522-
523534
private static Generator buildGenerator(
524535
final String entityName,
525536
final Property mappingProperty,

0 commit comments

Comments
 (0)