org.hibernate.persister.collection.AbstractCollectionPersister.java:
public void processQueuedOps(PersistentCollection collection, Serializable key, SessionImplementor session) throws HibernateException { if ( collection.hasQueuedOperations() ) { int nextIndex = getSize( key, session ); doProcessQueuedOps( collection, key, nextIndex, session ); }
}
Please note the line: int nextIndex = getSize( key, session );
It actually executes a query "select count xxx" which is expensive and has negative impact on performance.
More importantly, in the method doProcessQueuedOps:
@Deprecated protected void doProcessQueuedOps(PersistentCollection collection, Serializable key, int nextIndex, SessionImplementor session) throws HibernateException { doProcessQueuedOps( collection, key, session ); }
The param nextIndex is not even used.
It appears that the method doProcessQueuedOps(PersistentCollection collection, Serializable key, int nextIndex, SessionImplementor session) is already deprecated and is not supposed to be used any more.
The method processQueuedOps should call doProcessQueuedOps(PersistentCollection collection, Serializable key, SessionImplementor session) and no need to invoke getSize method that is very expensive.
In addition, in org.hibernate.persister.collection.OneToManyPersister.java, the following method also triggers unnecessary call getSize() that executes "select count.." query:
protected void doProcessQueuedOps(PersistentCollection collection, Serializable id, SessionImplementor session) throws HibernateException { writeIndex( collection, collection.queuedAdditionIterator(), id, getSize( id, session ), session ); }
|