is there a solution for batch insert via hibernate in partitioned postgresql table? currently i'm getting an error like this...

57286 [pool-1-thread-18] ERROR org.hibernate.jdbc.AbstractBatcher - Exception executing batch: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched( at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome( at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(

i have found this link but i can't find anywhere on the web is this problem solved or how it can be get around

+2  A: 

You might want to try using a custom Batcher by setting the hibernate.jdbc.factory_class property. Making sure hibernate won't check the update count of batch operations might fix your problem, you can achieve that by making your custom Batcher extend the class BatchingBatcher, and then overriding the method doExecuteBatch(...) to look like:

    protected void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException {
     if ( batchSize == 0 ) {
      log.debug( "no batched statements to execute" );
     else {
      if ( log.isDebugEnabled() ) {
       log.debug( "Executing batch size: " + batchSize );

      try {
//     checkRowCounts( ps.executeBatch(), ps );
      catch (RuntimeException re) {
       log.error( "Exception executing batch: ", re );
       throw re;
      finally {
       batchSize = 0;



Note that the new method doesn't check the results of executing the prepared statements. Keep in mind that making this change might affect hibernate in some unexpected way (or maybe not).

+2  A: 

thnx! it did the trick, no problems poped up, so far :) thing thou... i had to implement BatcherFactory class and put it int the persistence.xml file, like this:

property name="hibernate.jdbc.factory_class" value="" from that factory i've called my batcher implementation with the code above

ps hibernate core 3.2.6 GA

thanks once again

By ignoring the batch count does that fix your problem or does it just ignore the error?I'm having the same error and I can't tell why it's happening or what it means if I try to override the Batcher to skip it?
How is this working with Hibernate 3.2.6 GA The BatchingBatcher implementation has batchSize as a private field so extending it I do not have access to it.
it ignores the problem, but all the values are in the DB, so it does the trick for me...i extended the AbstractBatcher class

They say to use Two triggers in partitioned table or @SQLInset annotation Here : pages 21-26