as per below. please can you tell me whether or not this will work. i don't want to have to understand all of your code if i can avoid it. cheers. Paul
/**
* Perform an SQL UPDATE or SQL INSERT
*/
protected void updateOrInsert(final Serializable id,
final Object[] fields,
final Object[] oldFields,
final Object rowId,
final boolean[] includeProperty,
final int j,
final Object oldVersion,
final Object object,
final String sql,
final SessionImplementor session)
throws HibernateException {
if ( !isInverseTable( j ) ) {
boolean isRowToUpdate;
boolean isRowToInsert;
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
try{
isRowToUpdate = update( id, fields, oldFields, rowId, includeProperty, j, oldVersion, object, sql, session );
}
catch(StaleStateException he){
throw he;
}
catch(HibernateException he){
isRowToUpdate = false;
}
}
isRowToInsert = true;
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
try{
insert( id, fields, getPropertyInsertability(), j, getSQLInsertStrings()[j], object, session );
}
catch(StaleStateException he){
throw he;
}
catch(HibernateException he){
isRowToInsert = false;
}
}
// allow to throw exception
if(!isRowToInsert){
isRowToUpdate = update( id, fields, oldFields, rowId, includeProperty, j, oldVersion, object, sql, session );
}
}
}
|