@@ -172,16 +172,18 @@ static class CollectionAreCollectionFieldsDirty {
172172 @ Advice .Return (readOnly = false ) boolean returned ,
173173 @ FieldName String fieldName ,
174174 @ FieldValue Collection <?> collection ,
175- @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ) {
176- if ( !returned && $$_hibernate_collectionTracker != null ) {
177- final int size = $$_hibernate_collectionTracker .getSize ( fieldName );
178- if ( collection == null && size != -1 ) {
175+ @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ,
176+ @ Advice .FieldValue (value = EnhancerConstants .INTERCEPTOR_FIELD_NAME ) PersistentAttributeInterceptor $$_hibernate_attributeInterceptor ) {
177+ // Only look at initialized attributes, since value sameness is tracked via InlineDirtyCheckingHandler
178+ if ( !returned && $$_hibernate_collectionTracker != null && ( $$_hibernate_attributeInterceptor == null
179+ || $$_hibernate_attributeInterceptor .isAttributeLoaded ( fieldName ) ) ) {
180+ if ( collection == null && $$_hibernate_collectionTracker .getSize ( fieldName ) != -1 ) {
179181 returned = true ;
180182 }
181183 else if ( collection != null ) {
182184 // We only check sizes of non-persistent or initialized persistent collections
183185 if ( ( !( collection instanceof PersistentCollection ) || ( (PersistentCollection <?>) collection ).wasInitialized () )
184- && size != collection .size () ) {
186+ && $$_hibernate_collectionTracker . getSize ( fieldName ) != collection .size () ) {
185187 returned = true ;
186188 }
187189 }
@@ -195,16 +197,18 @@ static class MapAreCollectionFieldsDirty {
195197 @ Advice .Return (readOnly = false ) boolean returned ,
196198 @ FieldName String fieldName ,
197199 @ FieldValue Map <?, ?> map ,
198- @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ) {
199- if ( !returned && $$_hibernate_collectionTracker != null ) {
200- final int size = $$_hibernate_collectionTracker .getSize ( fieldName );
201- if ( map == null && size != -1 ) {
200+ @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ,
201+ @ Advice .FieldValue (value = EnhancerConstants .INTERCEPTOR_FIELD_NAME ) PersistentAttributeInterceptor $$_hibernate_attributeInterceptor ) {
202+ // Only look at initialized attributes, since value sameness is tracked via InlineDirtyCheckingHandler
203+ if ( !returned && $$_hibernate_collectionTracker != null && ( $$_hibernate_attributeInterceptor == null
204+ || $$_hibernate_attributeInterceptor .isAttributeLoaded ( fieldName ) ) ) {
205+ if ( map == null && $$_hibernate_collectionTracker .getSize ( fieldName ) != -1 ) {
202206 returned = true ;
203207 }
204208 else if ( map != null ) {
205209 // We only check sizes of non-persistent or initialized persistent collections
206210 if ( ( !( map instanceof PersistentCollection ) || ( (PersistentCollection ) map ).wasInitialized () )
207- && size != map .size () ) {
211+ && $$_hibernate_collectionTracker . getSize ( fieldName ) != map .size () ) {
208212 returned = true ;
209213 }
210214 }
@@ -214,20 +218,22 @@ else if ( map != null ) {
214218
215219 static class CollectionGetCollectionFieldDirtyNames {
216220 @ Advice .OnMethodExit
217- static void $$_hibernate_areCollectionFieldsDirty (
221+ static void $$_hibernate_getCollectionFieldDirtyNames (
218222 @ FieldName String fieldName ,
219223 @ FieldValue Collection <?> collection ,
220224 @ Advice .Argument (0 ) DirtyTracker tracker ,
221- @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ) {
222- if ( $$_hibernate_collectionTracker != null ) {
223- final int size = $$_hibernate_collectionTracker .getSize ( fieldName );
224- if ( collection == null && size != -1 ) {
225+ @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ,
226+ @ Advice .FieldValue (value = EnhancerConstants .INTERCEPTOR_FIELD_NAME ) PersistentAttributeInterceptor $$_hibernate_attributeInterceptor ) {
227+ // Only look at initialized attributes, since value sameness is tracked via InlineDirtyCheckingHandler
228+ if ( $$_hibernate_collectionTracker != null && ( $$_hibernate_attributeInterceptor == null
229+ || $$_hibernate_attributeInterceptor .isAttributeLoaded ( fieldName ) ) ) {
230+ if ( collection == null && $$_hibernate_collectionTracker .getSize ( fieldName ) != -1 ) {
225231 tracker .add ( fieldName );
226232 }
227233 else if ( collection != null ) {
228234 // We only check sizes of non-persistent or initialized persistent collections
229235 if ( ( !( collection instanceof PersistentCollection ) || ( (PersistentCollection <?>) collection ).wasInitialized () )
230- && size != collection .size () ) {
236+ && $$_hibernate_collectionTracker . getSize ( fieldName ) != collection .size () ) {
231237 tracker .add ( fieldName );
232238 }
233239 }
@@ -237,20 +243,22 @@ else if ( collection != null ) {
237243
238244 static class MapGetCollectionFieldDirtyNames {
239245 @ Advice .OnMethodExit
240- static void $$_hibernate_areCollectionFieldsDirty (
246+ static void $$_hibernate_getCollectionFieldDirtyNames (
241247 @ FieldName String fieldName ,
242248 @ FieldValue Map <?, ?> map ,
243249 @ Advice .Argument (0 ) DirtyTracker tracker ,
244- @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ) {
245- if ( $$_hibernate_collectionTracker != null ) {
246- final int size = $$_hibernate_collectionTracker .getSize ( fieldName );
247- if ( map == null && size != -1 ) {
250+ @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ,
251+ @ Advice .FieldValue (value = EnhancerConstants .INTERCEPTOR_FIELD_NAME ) PersistentAttributeInterceptor $$_hibernate_attributeInterceptor ) {
252+ // Only look at initialized attributes, since value sameness is tracked via InlineDirtyCheckingHandler
253+ if ( $$_hibernate_collectionTracker != null && ( $$_hibernate_attributeInterceptor == null
254+ || $$_hibernate_attributeInterceptor .isAttributeLoaded ( fieldName ) ) ) {
255+ if ( map == null && $$_hibernate_collectionTracker .getSize ( fieldName ) != -1 ) {
248256 tracker .add ( fieldName );
249257 }
250258 else if ( map != null ) {
251259 // We only check sizes of non-persistent or initialized persistent collections
252260 if ( ( !( map instanceof PersistentCollection ) || ( (PersistentCollection <?>) map ).wasInitialized () )
253- && size != map .size () ) {
261+ && $$_hibernate_collectionTracker . getSize ( fieldName ) != map .size () ) {
254262 tracker .add ( fieldName );
255263 }
256264 }
@@ -260,16 +268,14 @@ else if ( map != null ) {
260268
261269 static class CollectionGetCollectionClearDirtyNames {
262270 @ Advice .OnMethodExit
263- static void $$_hibernate_clearDirtyCollectionNames (
271+ static void $$_hibernate_removeDirtyFields (
264272 @ FieldName String fieldName ,
265273 @ FieldValue Collection <?> collection ,
266274 @ Advice .Argument (value = 0 , readOnly = false ) LazyAttributeLoadingInterceptor lazyInterceptor ,
267275 @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ) {
268- if ( lazyInterceptor == null || lazyInterceptor .isAttributeLoaded ( fieldName ) ) {
269- if ( collection == null || collection instanceof PersistentCollection && !( (PersistentCollection <?>) collection ).wasInitialized () ) {
270- $$_hibernate_collectionTracker .add ( fieldName , -1 );
271- }
272- else {
276+ // Only look at initialized attributes, since value sameness is tracked via InlineDirtyCheckingHandler
277+ if ( ( lazyInterceptor == null || lazyInterceptor .isAttributeLoaded ( fieldName ) ) && collection != null ) {
278+ if ( !( collection instanceof PersistentCollection ) || ( (PersistentCollection <?>) collection ).wasInitialized () ) {
273279 $$_hibernate_collectionTracker .add ( fieldName , collection .size () );
274280 }
275281 }
@@ -278,16 +284,14 @@ static class CollectionGetCollectionClearDirtyNames {
278284
279285 static class MapGetCollectionClearDirtyNames {
280286 @ Advice .OnMethodExit
281- static void $$_hibernate_clearDirtyCollectionNames (
287+ static void $$_hibernate_removeDirtyFields (
282288 @ FieldName String fieldName ,
283289 @ FieldValue Map <?, ?> map ,
284290 @ Advice .Argument (value = 0 , readOnly = false ) LazyAttributeLoadingInterceptor lazyInterceptor ,
285291 @ Advice .FieldValue (EnhancerConstants .TRACKER_COLLECTION_NAME ) CollectionTracker $$_hibernate_collectionTracker ) {
286- if ( lazyInterceptor == null || lazyInterceptor .isAttributeLoaded ( fieldName ) ) {
287- if ( map == null || map instanceof PersistentCollection && !( (PersistentCollection <?>) map ).wasInitialized () ) {
288- $$_hibernate_collectionTracker .add ( fieldName , -1 );
289- }
290- else {
292+ // Only look at initialized attributes, since value sameness is tracked via InlineDirtyCheckingHandler
293+ if ( ( lazyInterceptor == null || lazyInterceptor .isAttributeLoaded ( fieldName ) ) && map != null ) {
294+ if ( !( map instanceof PersistentCollection ) || ( (PersistentCollection <?>) map ).wasInitialized () ) {
291295 $$_hibernate_collectionTracker .add ( fieldName , map .size () );
292296 }
293297 }
0 commit comments