mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-20 01:55:02 +00:00
HHH-16379 @DynamicUpdate and 'enableDirtyTracking=true' leads to wrong update statement
This commit is contained in:
parent
198ede22e4
commit
8e8a554eb9
@ -2448,7 +2448,25 @@ public int[] resolveDirtyAttributeIndexes(
|
|||||||
|
|
||||||
if ( attributeNames.length != 0 ) {
|
if ( attributeNames.length != 0 ) {
|
||||||
final boolean[] propertyUpdateability = entityMetamodel.getPropertyUpdateability();
|
final boolean[] propertyUpdateability = entityMetamodel.getPropertyUpdateability();
|
||||||
// Sort attribute names so that we can traverse mappings efficiently
|
if ( superMappingType == null ) {
|
||||||
|
/*
|
||||||
|
Sort attribute names so that we can traverse mappings efficiently
|
||||||
|
we cannot do this when there is a supertype because given:
|
||||||
|
|
||||||
|
class SuperEntity {
|
||||||
|
private String bSuper;
|
||||||
|
private String aSuper;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChildEntity extends SuperEntity {
|
||||||
|
private String aChild;
|
||||||
|
private String bChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
`attributeMappings` contains { aSuper, bSuper, aChild, bChild }
|
||||||
|
while the sorted `attributeNames` { aChild, aSuper, bChild, bSuper }
|
||||||
|
*/
|
||||||
|
|
||||||
Arrays.sort( attributeNames );
|
Arrays.sort( attributeNames );
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
||||||
@ -2477,6 +2495,15 @@ public int[] resolveDirtyAttributeIndexes(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
for ( String attributeName : attributeNames ) {
|
||||||
|
final Integer index = entityMetamodel.getPropertyIndexOrNull( attributeName );
|
||||||
|
if ( index != null && propertyUpdateability[index] && !fields.contains( index ) ) {
|
||||||
|
fields.add( index );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return toIntArray( fields );
|
return toIntArray( fields );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user