@@ -2510,6 +2510,13 @@ protected String[] getSubclassPropertyNameClosure() {
2510
2510
return subclassPropertyNameClosure ;
2511
2511
}
2512
2512
2513
+ private static boolean isPrefix (final AttributeMapping attributeMapping , final String currentAttributeName ) {
2514
+ final String attributeName = attributeMapping .getAttributeName ();
2515
+ final int nameLength = attributeName .length ();
2516
+ return currentAttributeName .startsWith ( attributeName )
2517
+ && ( currentAttributeName .length () == nameLength || currentAttributeName .charAt (nameLength ) == '.' );
2518
+ }
2519
+
2513
2520
@ Override
2514
2521
public int [] resolveAttributeIndexes (String [] attributeNames ) {
2515
2522
if ( attributeNames == null || attributeNames .length == 0 ) {
@@ -2522,11 +2529,7 @@ public int[] resolveAttributeIndexes(String[] attributeNames) {
2522
2529
2523
2530
int index = 0 ;
2524
2531
for ( final AttributeMapping attributeMapping : attributeMappings ) {
2525
- final String attributeName = attributeMapping .getAttributeName ();
2526
- final int nameLength = attributeName .length ();
2527
- final String currentAttributeName = attributeNames [index ];
2528
- if ( currentAttributeName .startsWith ( attributeName ) && (
2529
- ( currentAttributeName .length () == nameLength || currentAttributeName .charAt ( nameLength ) == '.' ) ) ) {
2532
+ if ( isPrefix ( attributeMapping , attributeNames [index ] ) ) {
2530
2533
fields .add ( attributeMapping .getStateArrayPosition () );
2531
2534
index ++;
2532
2535
if ( index < attributeNames .length ) {
@@ -2565,19 +2568,10 @@ public int[] resolveDirtyAttributeIndexes(
2565
2568
// We have to check the state for "mutable" properties as dirty tracking isn't aware of mutable types
2566
2569
final Type [] propertyTypes = entityMetamodel .getPropertyTypes ();
2567
2570
final boolean [] propertyCheckability = entityMetamodel .getPropertyCheckability ();
2568
- for ( int i = mutablePropertiesIndexes .nextSetBit (0 ); i >= 0 ; i = mutablePropertiesIndexes .nextSetBit (i + 1 ) ) {
2571
+ for ( int i = mutablePropertiesIndexes .nextSetBit (0 ); i >= 0 ;
2572
+ i = mutablePropertiesIndexes .nextSetBit (i + 1 ) ) {
2569
2573
// This is kindly borrowed from org.hibernate.type.TypeHelper.findDirty
2570
- final boolean dirty = currentState [i ] != LazyPropertyInitializer .UNFETCHED_PROPERTY &&
2571
- // Consider mutable properties as dirty if we don't have a previous state
2572
- ( previousState == null || previousState [i ] == LazyPropertyInitializer .UNFETCHED_PROPERTY ||
2573
- ( propertyCheckability [i ]
2574
- && propertyTypes [i ].isDirty (
2575
- previousState [i ],
2576
- currentState [i ],
2577
- propertyColumnUpdateable [i ],
2578
- session
2579
- ) ) );
2580
- if ( dirty ) {
2574
+ if ( isDirty ( currentState , previousState , propertyTypes , propertyCheckability , i , session ) ) {
2581
2575
fields .add ( i );
2582
2576
}
2583
2577
}
@@ -2591,11 +2585,8 @@ public int[] resolveDirtyAttributeIndexes(
2591
2585
int index = 0 ;
2592
2586
for ( final AttributeMapping attributeMapping : attributeMappings ) {
2593
2587
final String attributeName = attributeMapping .getAttributeName ();
2594
- final int nameLength = attributeName .length ();
2595
- final String currentAttributeName = attributeNames [index ];
2596
- final int position = attributeMapping .getStateArrayPosition ();
2597
- if ( currentAttributeName .startsWith ( attributeName ) && (
2598
- ( currentAttributeName .length () == nameLength || currentAttributeName .charAt ( nameLength ) == '.' ) ) ) {
2588
+ if ( isPrefix ( attributeMapping , attributeNames [index ] ) ) {
2589
+ final int position = attributeMapping .getStateArrayPosition ();
2599
2590
if ( propertyUpdateability [position ] && !fields .contains ( position ) ) {
2600
2591
fields .add ( position );
2601
2592
}
@@ -2621,6 +2612,27 @@ public int[] resolveDirtyAttributeIndexes(
2621
2612
return ArrayHelper .toIntArray ( fields );
2622
2613
}
2623
2614
2615
+ private boolean isDirty (
2616
+ Object [] currentState ,
2617
+ Object [] previousState ,
2618
+ Type [] propertyTypes ,
2619
+ boolean [] propertyCheckability ,
2620
+ int i ,
2621
+ SessionImplementor session ) {
2622
+ return currentState [i ] != LazyPropertyInitializer .UNFETCHED_PROPERTY
2623
+ // Consider mutable properties as dirty if we don't have a previous state
2624
+ && ( previousState == null
2625
+ || previousState [i ] == LazyPropertyInitializer .UNFETCHED_PROPERTY
2626
+ || propertyCheckability [i ]
2627
+ && propertyTypes [i ].isDirty (
2628
+ previousState [i ],
2629
+ currentState [i ],
2630
+ propertyColumnUpdateable [i ],
2631
+ session
2632
+ )
2633
+ );
2634
+ }
2635
+
2624
2636
protected String [] getSubclassColumnAliasClosure () {
2625
2637
return subclassColumnAliasClosure ;
2626
2638
}
@@ -2631,17 +2643,17 @@ protected String[] getSubclassFormulaAliasClosure() {
2631
2643
2632
2644
@ Override
2633
2645
public String [] getSubclassPropertyColumnAliases (String propertyName , String suffix ) {
2634
- String [] rawAliases = subclassPropertyAliases .get ( propertyName );
2635
-
2646
+ final String [] rawAliases = subclassPropertyAliases .get ( propertyName );
2636
2647
if ( rawAliases == null ) {
2637
2648
return null ;
2638
2649
}
2639
-
2640
- String [] result = new String [rawAliases .length ];
2641
- for ( int i = 0 ; i < rawAliases .length ; i ++ ) {
2642
- result [i ] = new Alias ( suffix ).toUnquotedAliasString ( rawAliases [i ] );
2650
+ else {
2651
+ final String [] result = new String [rawAliases .length ];
2652
+ for ( int i = 0 ; i < rawAliases .length ; i ++ ) {
2653
+ result [i ] = new Alias ( suffix ).toUnquotedAliasString ( rawAliases [i ] );
2654
+ }
2655
+ return result ;
2643
2656
}
2644
- return result ;
2645
2657
}
2646
2658
2647
2659
@ Override
0 commit comments