| One problem I still see is that Collection.size() method is used to determine collection dirtyness which hit's the persistence store for each PersistentCollection property. Why don't you consult
org.hibernate.collection.spi.PersistentCollection.isDirty()
in case of PersistentCollections? In current implementation, if the entity class is instanceof SelfDirtinessTracker, $$_hibernate_clearDirtyAttributes is invoked for it after initialization by
org.hibernate.tuple.entity.PojoEntityTuplizer.afterInitialize(Object, SharedSessionContractImplementor).
public void $$_hibernate_removeDirtyFields(LazyAttributeLoadingInterceptor paramLazyAttributeLoadingInterceptor)
{
if ((this.$$_hibernate_collectionTracker instanceof LazyAttributeLoadingInterceptor)) {
paramLazyAttributeLoadingInterceptor = (LazyAttributeLoadingInterceptor)this.$$_hibernate_collectionTracker;
}
if ((paramLazyAttributeLoadingInterceptor == null) || (paramLazyAttributeLoadingInterceptor.isAttributeLoaded("someCollectionAttribute"))) {
if (this.someCollectionAttribute == null) {
this.$$_hibernate_collectionTracker.add("someCollectionAttribute", -1);
} else {
this.$$_hibernate_collectionTracker.add("someCollectionAttribute", this.someCollectionAttribute.size());
}
}
where this.someCollectionAttribute.size() initializes the lazy collection, causing new entities to be loaded which may have lazy collection properties too. If the collection is EXTRA lazy, the endless loading loop is prevented but nevertheless a "SELECT count(ID) from ..." is sent once for every PersistentCollection when invoking size() the first time which is still quite slow. I assume the dirtyCheck enhancements' purpose is to gain performance which is what I'd like to get  Kind regards. |