|
Hibernate version:3.0
NonBatchingBatcher.addToBatch throws a HibernateException in this code block:
if ( expectedRowCount>rowCount ) {
throw new HibernateException(
"Unexpected row count: " + rowCount +
" expected: " + expectedRowCount
);
}
This code is indirectly called from BasicEntityPersister.updateOrInsert in this code:
if ( !isInverseTable( j ) ) {
final boolean isRowToUpdate;
if ( isNullableTable( j ) && oldFields != null && isAllNull( oldFields, j ) ) {
//don't bother trying to update, we know there is no row there yet
isRowToUpdate = false;
}
else if ( isNullableTable( j ) && isAllNull( fields, j ) ) {
//if all fields are null, we might need to delete existing row
isRowToUpdate = true;
delete( id, oldVersion, j, object, getSQLDeleteStrings()[j], session );
}
else {
//there is probably a row there, so try to update
//if no rows were updated, we will find out
isRowToUpdate = update( id, fields, oldFields, rowId, includeProperty, j, oldVersion, object, sql, session );
}
if ( !isRowToUpdate && !isAllNull( fields, j ) ) {
// assume that the row was not there since it previously had only null
// values, so do an INSERT instead
//TODO: does not respect dynamic-insert
insert( id, fields, getPropertyInsertability(), j, getSQLInsertStrings()[j], object, session ); // NOT EXECUTED IF EXCEPTION THROWN ABOVE
}
}
So the call to update(...) can throw an exception (from NonBatchingBatcher.addToBatch) which isn't caught here. This means that an update might fail; because the row does not exist say; and the insert(...) on the line below will not be executed.
Is this correct behaviour? Should some updates fail over to inserts and other not?
Regards,
Paul
|