Hi all,
I'm working with a postgres partitioned database and to avoid:
Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
I'm using a implementation of AbstractBatcher that doesn't do the checkRowCounts
Code:
public class BatchingBatcherAntica extends AbstractBatcher {
private int batchSize;
private Expectation[] expectations;
public BatchingBatcherAntica(ConnectionManager connectionManager, Interceptor interceptor) {
super( connectionManager, interceptor );
expectations = new Expectation[ getFactory().getSettings().getJdbcBatchSize() ];
}
public void addToBatch(Expectation expectation) throws SQLException, HibernateException {
if ( !expectation.canBeBatched() ) {
throw new HibernateException( "attempting to batch an operation which cannot be batched" );
}
PreparedStatement batchUpdate = getStatement();
batchUpdate.addBatch();
expectations[ batchSize++ ] = expectation;
if ( batchSize == getFactory().getSettings().getJdbcBatchSize() ) {
doExecuteBatch( batchUpdate );
}
}
protected void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException {
if ( batchSize == 0 ) {
//log.debug( "no batched statements to execute" );
}
else {
try {
//checkRowCounts( ps.executeBatch(), ps );
ps.executeBatch();
}
catch (RuntimeException re) {
//log.error( "Exception executing batch: ", re );
throw re;
}
finally {
batchSize = 0;
}
}
}
}
I'm not sure about the consecuencies of doing this... Anyone can help me with an explanation to figure out if this is a good option or not?
What's the main propose of this function? In which cases is usless...? I looked for the hibernate javadoc but nothing is there.
Thanks in advance for any help or links