throws HibernateException {
if ( ArrayHelper.isAllFalse( elementColumnIsSettable ) ) return 0;
int count = 0;
int i = 0;
Iterator entries = collection.entries( this );
PropertyMetadataProvider metadataProvider = new PropertyMetadataProvider()
.gridDialect(gridDialect)
.tableName( getTableName() )
.key( key )
.keyColumnNames( getKeyColumnNames() )
.keyGridType( getKeyGridType() )
.collectionPersister( this )
.session( session );
while ( entries.hasNext() ) {
Object entry = entries.next();
if ( collection.needsUpdating( entry, i, elementType ) ) {
//find the matching element
RowKey assocEntryKey = getTupleKeyForUpdate( key, collection, session, i, entry );
Tuple assocEntryTuple = metadataProvider.getCollectionMetadata().get( assocEntryKey );
if ( assocEntryTuple == null ) {
throw new AssertionFailure( "Updating a collection tuple that is not present: " +
"table {" + getTableName() + "} collectionKey {" + key + "} entry {" + entry + "}" );
}
//update the matching element
//FIXME update the associated entity key data
updateInverseSideOfAssociationNavigation( session, assocEntryTuple, Action.REMOVE, assocEntryKey );
getElementGridType().nullSafeSet(
assocEntryTuple,
collection.getElement( entry ),
getElementColumnNames(),
session
);
updateInverseSideOfAssociationNavigation( session, assocEntryTuple, Action.ADD, assocEntryKey );
count++;
}
i++;
}
//need to put the data back in the cache
metadataProvider.flushToCache();
return count;
}