1111import java .util .Locale ;
1212import java .util .function .Supplier ;
1313
14- import org .hibernate .AssertionFailure ;
1514import org .hibernate .HibernateException ;
1615import org .hibernate .Internal ;
1716import org .hibernate .StaleObjectStateException ;
@@ -200,7 +199,6 @@ public GeneratedValues update(
200199
201200 final boolean [] attributeUpdateability ;
202201 boolean forceDynamicUpdate ;
203-
204202 if ( entityPersister ().getEntityMetamodel ().isDynamicUpdate () && dirtyAttributeIndexes != null ) {
205203 attributeUpdateability = getPropertiesToUpdate ( dirtyAttributeIndexes , hasDirtyCollection );
206204 forceDynamicUpdate = true ;
@@ -374,21 +372,15 @@ private static boolean includedInLock(
374372 int position ,
375373 SingularAttributeMapping attribute ,
376374 EntityPersister persister ) {
377- switch ( persister .optimisticLockStyle () ) {
378- case NONE :
379- return false ;
380- case VERSION :
381- return versionMapping != null
382- && versionMapping .getVersionAttribute () == attribute ;
375+ return switch ( persister .optimisticLockStyle () ) {
376+ case NONE -> false ;
377+ case VERSION -> versionMapping != null
378+ && versionMapping .getVersionAttribute () == attribute ;
383379// && updateableAttributeIndexes[position];
384- case ALL :
385- return attribute .getAttributeMetadata ().isIncludedInOptimisticLocking ();
386- case DIRTY :
387- return attribute .getAttributeMetadata ().isIncludedInOptimisticLocking ()
388- && dirtinessChecker .include ( position , attribute );
389- default :
390- throw new AssertionFailure ( "unknown OptimisticLockStyle" );
391- }
380+ case ALL -> attribute .getAttributeMetadata ().isIncludedInOptimisticLocking ();
381+ case DIRTY -> attribute .getAttributeMetadata ().isIncludedInOptimisticLocking ()
382+ && dirtinessChecker .include ( position , attribute );
383+ };
392384 }
393385
394386 protected Supplier <GeneratedValues > handlePotentialImplicitForcedVersionIncrement (
@@ -988,7 +980,7 @@ private MutationExecutor updateVersionExecutor(
988980 boolean dynamicUpdate ,
989981 boolean batching ) {
990982 if ( batching ) {
991- return updateVersionExecutor (session , group ,dynamicUpdate );
983+ return updateVersionExecutor ( session , group , dynamicUpdate );
992984 }
993985 return mutationExecutorService .createExecutor ( NoBatchKeyAccess .INSTANCE , group , session );
994986
@@ -1228,9 +1220,7 @@ private void applyAttributeUpdateDetails(
12281220 TableUpdateBuilder <?> tableUpdateBuilder ,
12291221 SharedSessionContractImplementor session ) {
12301222 final Generator generator = attributeMapping .getGenerator ();
1231- if ( isValueGenerated ( generator )
1232- && ( session == null && generator .generatedOnExecution () || generator .generatedOnExecution ( entity , session ) )
1233- && isValueGenerationInSql ( generator , dialect ) ) {
1223+ if ( needsValueGeneration ( entity , session , generator ) ) {
12341224 handleValueGeneration ( attributeMapping , updateGroupBuilder , (OnExecutionGenerator ) generator );
12351225 }
12361226 else if ( versionMapping != null
@@ -1247,6 +1237,12 @@ else if ( versionMapping != null
12471237 }
12481238 }
12491239
1240+ private boolean needsValueGeneration (Object entity , SharedSessionContractImplementor session , Generator generator ) {
1241+ return isValueGenerated ( generator )
1242+ && (session == null && generator .generatedOnExecution () || generator .generatedOnExecution ( entity , session ) )
1243+ && isValueGenerationInSql ( generator , dialect );
1244+ }
1245+
12501246 /**
12511247 * Contains the aggregated analysis of the update values to determine
12521248 * what SQL UPDATE statement(s) should be used to update the entity
@@ -1608,19 +1604,19 @@ private MutationOperationGroup buildStaticUpdateGroup() {
16081604 null ,
16091605 null ,
16101606 null ,
1611- (index ,attribute ) -> isValueGenerated ( attribute .getGenerator () ) && isValueGenerationInSql ( attribute .getGenerator (), dialect () )
1607+ (index ,attribute ) ->
1608+ isValueGenerated ( attribute .getGenerator () )
1609+ && isValueGenerationInSql ( attribute .getGenerator (), dialect () )
16121610 || entityPersister ().getPropertyUpdateability ()[index ],
1613- (index ,attribute ) -> {
1614- switch ( entityPersister ().optimisticLockStyle () ) {
1615- case ALL :
1616- return true ;
1617- case VERSION :
1618- final EntityVersionMapping versionMapping = entityPersister ().getVersionMapping ();
1619- return versionMapping != null && attribute == versionMapping .getVersionAttribute ();
1620- default :
1621- return false ;
1622- }
1623- },
1611+ (index ,attribute ) ->
1612+ switch ( entityPersister ().optimisticLockStyle () ) {
1613+ case ALL -> true ;
1614+ case VERSION -> {
1615+ final EntityVersionMapping versionMapping = entityPersister ().getVersionMapping ();
1616+ yield versionMapping != null && attribute == versionMapping .getVersionAttribute ();
1617+ }
1618+ default -> false ;
1619+ },
16241620 (index ,attribute ) -> true ,
16251621 "" , // pass anything here to generate the row id restriction if possible
16261622 false ,
0 commit comments