I have try to profile a little what's happen. In fact in my sample, I retrieve from DB a Protocol objects that contains a List of parameters.
Protocol ->*Parameter
None of these objects have been modified. Having a look in DefaultFlushEntityEventListener.onFlushEntity method I can see that with enhanced classes the mightBeDirty flag is turned to false (with non enhanced class it was to true). The problem comes from the list of Parameter includes in the Protocol.
In the onFlushEntity, since my protocol has collections I go through
Code:
if ( persister.hasCollections() ) {
new FlushVisitor(session, entity).processEntityPropertyValues(values, types);
}
Method that seems to be time consumming is FlushVisitor.processCollection. If I had at the beginning to stop the process when collections are not dirty, it divide the flush time by 2.
Code:
if (collection!=null) {
final PersistentCollection coll;
if ( type.hasHolder( getSession().getEntityMode() ) ) {
coll = getSession().getPersistenceContext().getCollectionHolder(collection);
}
else {
coll = (PersistentCollection) collection;
}
//////////////////////////////////////////// MODIF ///////////
if (!coll.isDirty()) return null;
Collections.processReachableCollection( coll, type, owner, getSession() );
}
With that modif, flush is still a bit longer but it is much better. Maybe I have break something ? but it seems to work. Any comment are welcome !
I will continue to profile my code to see what's is time consumming.