Skip to content

Commit aaebcdf

Browse files
barreirogbadner
authored andcommitted
HHH-11506 - Fix update of lazy attributes when there are attributes not loaded
HHH-11506 - Deprecate methods HHH-11506 : Added original TypeHelper#findModfied and deprecated; changed deprecated methods to call the new methods.
1 parent 12a1b3c commit aaebcdf

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,7 +4210,6 @@ public int[] findDirty(Object[] currentState, Object[] previousState, Object ent
42104210
currentState,
42114211
previousState,
42124212
propertyColumnUpdateable,
4213-
hasUninitializedLazyProperties( entity ),
42144213
session
42154214
);
42164215
if ( props == null ) {
@@ -4242,7 +4241,6 @@ public int[] findModified(Object[] old, Object[] current, Object entity, SharedS
42424241
old,
42434242
propertyColumnUpdateable,
42444243
getPropertyUpdateability(),
4245-
hasUninitializedLazyProperties( entity ),
42464244
session
42474245
);
42484246
if ( props == null ) {

hibernate-core/src/main/java/org/hibernate/tuple/AbstractNonIdentifierAttribute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public boolean isDirtyCheckable() {
8686

8787
@Override
8888
public boolean isDirtyCheckable(boolean hasUninitializedProperties) {
89-
return isDirtyCheckable() && ( !hasUninitializedProperties || !isLazy() );
89+
return isDirtyCheckable();
9090
}
9191

9292
@Override

hibernate-core/src/main/java/org/hibernate/tuple/NonIdentifierAttribute.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public interface NonIdentifierAttribute extends Attribute, AttributeDefinition {
2424

2525
public boolean isNullable();
2626

27+
/**
28+
* @deprecated Use {@link org.hibernate.tuple.NonIdentifierAttribute#isDirtyCheckable()} instead
29+
*/
30+
@Deprecated
2731
public boolean isDirtyCheckable(boolean hasUninitializedProperties);
2832

2933
public boolean isDirtyCheckable();

hibernate-core/src/main/java/org/hibernate/type/TypeHelper.java

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,23 +279,49 @@ else if ( !types[i].isAssociationType() ) {
279279
* @param includeColumns Columns to be included in the dirty checking, per property
280280
* @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
281281
* @param session The session from which the dirty check request originated.
282-
*
282+
*
283283
* @return Array containing indices of the dirty properties, or null if no properties considered dirty.
284+
*
285+
* @deprecated Use {org.hibernate.type.TypeHelper{@link #findDirty(NonIdentifierAttribute[], Object[], Object[], boolean[][], SharedSessionContractImplementor)} indtead
284286
*/
287+
@Deprecated
285288
public static int[] findDirty(
286289
final NonIdentifierAttribute[] properties,
287290
final Object[] currentState,
288291
final Object[] previousState,
289292
final boolean[][] includeColumns,
290293
final boolean anyUninitializedProperties,
291294
final SharedSessionContractImplementor session) {
295+
return findDirty( properties, currentState, previousState, includeColumns, session );
296+
}
297+
298+
/**
299+
* Determine if any of the given field values are dirty, returning an array containing
300+
* indices of the dirty fields.
301+
* <p/>
302+
* If it is determined that no fields are dirty, null is returned.
303+
*
304+
* @param properties The property definitions
305+
* @param currentState The current state of the entity
306+
* @param previousState The baseline state of the entity
307+
* @param includeColumns Columns to be included in the dirty checking, per property
308+
* @param session The session from which the dirty check request originated.
309+
*
310+
* @return Array containing indices of the dirty properties, or null if no properties considered dirty.
311+
*/
312+
public static int[] findDirty(
313+
final NonIdentifierAttribute[] properties,
314+
final Object[] currentState,
315+
final Object[] previousState,
316+
final boolean[][] includeColumns,
317+
final SharedSessionContractImplementor session) {
292318
int[] results = null;
293319
int count = 0;
294320
int span = properties.length;
295321

296322
for ( int i = 0; i < span; i++ ) {
297323
final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
298-
&& properties[i].isDirtyCheckable( anyUninitializedProperties )
324+
&& properties[i].isDirtyCheckable()
299325
&& properties[i].getType().isDirty( previousState[i], currentState[i], includeColumns[i], session );
300326
if ( dirty ) {
301327
if ( results == null ) {
@@ -330,7 +356,11 @@ public static int[] findDirty(
330356
* @param session The session from which the dirty check request originated.
331357
*
332358
* @return Array containing indices of the modified properties, or null if no properties considered modified.
359+
*
360+
* @deprecated Use {@link #findModified(NonIdentifierAttribute[], Object[], Object[], boolean[][], boolean[], boolean, SharedSessionContractImplementor)}
361+
* instead.
333362
*/
363+
@Deprecated
334364
public static int[] findModified(
335365
final NonIdentifierAttribute[] properties,
336366
final Object[] currentState,
@@ -339,14 +369,40 @@ public static int[] findModified(
339369
final boolean[] includeProperties,
340370
final boolean anyUninitializedProperties,
341371
final SharedSessionContractImplementor session) {
372+
return findModified( properties, currentState, previousState, includeColumns, includeProperties, session );
373+
}
374+
375+
/**
376+
* Determine if any of the given field values are modified, returning an array containing
377+
* indices of the modified fields.
378+
* <p/>
379+
* If it is determined that no fields are dirty, null is returned.
380+
*
381+
* @param properties The property definitions
382+
* @param currentState The current state of the entity
383+
* @param previousState The baseline state of the entity
384+
* @param includeColumns Columns to be included in the mod checking, per property
385+
* @param includeProperties Array of property indices that identify which properties participate in check
386+
* @param anyUninitializedProperties Does the entity currently hold any uninitialized property values?
387+
* @param session The session from which the dirty check request originated.
388+
*
389+
* @return Array containing indices of the modified properties, or null if no properties considered modified.
390+
**/
391+
public static int[] findModified(
392+
final NonIdentifierAttribute[] properties,
393+
final Object[] currentState,
394+
final Object[] previousState,
395+
final boolean[][] includeColumns,
396+
final boolean[] includeProperties,
397+
final SharedSessionContractImplementor session) {
342398
int[] results = null;
343399
int count = 0;
344400
int span = properties.length;
345401

346402
for ( int i = 0; i < span; i++ ) {
347403
final boolean modified = currentState[ i ] != LazyPropertyInitializer.UNFETCHED_PROPERTY
348404
&& includeProperties[ i ]
349-
&& properties[ i ].isDirtyCheckable( anyUninitializedProperties )
405+
&& properties[ i ].isDirtyCheckable()
350406
&& properties[ i ].getType().isModified( previousState[ i ], currentState[ i ], includeColumns[ i ], session );
351407
if ( modified ) {
352408
if ( results == null ) {

hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public boolean hasLazyLoadableAttributes(UnloadedClass classDescriptor) {
140140

141141
@Test
142142
@TestForIssue( jiraKey = "HHH-11173" )
143-
@RequiresDialectFeature( value = DialectChecks.SupportsIdentityColumns.class)
143+
@RequiresDialectFeature( DialectChecks.SupportsIdentityColumns.class)
144144
public void testLazyCache() {
145145
EnhancerTestUtils.runEnhancerTestTask( LazyInCacheTestTask.class );
146146
}
@@ -181,6 +181,17 @@ public void testLazyGroupsUpdateSimple() {
181181
EnhancerTestUtils.runEnhancerTestTask( SimpleLazyGroupUpdateTestTask.class );
182182
}
183183

184+
@Test
185+
@TestForIssue( jiraKey = "HHH-11506" )
186+
public void testLazyGroupsUpdateWithoutDirtyChecking() {
187+
EnhancerTestUtils.runEnhancerTestTask( SimpleLazyGroupUpdateTestTask.class , new EnhancerTestContext() {
188+
@Override
189+
public boolean doDirtyCheckingInline(UnloadedClass classDescriptor) {
190+
return false;
191+
}
192+
} );
193+
}
194+
184195
@Test
185196
public void testLazyCollectionNoTransactionHandling() {
186197
EnhancerTestUtils.runEnhancerTestTask( LazyCollectionNoTransactionLoadingTestTask.class );

0 commit comments

Comments
 (0)