hibernate insert batch with partitioned postgresql

前端 未结 6 1624
一生所求
一生所求 2021-02-07 21:27

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

ERROR org.hibernate.jdbc.Abstra         


        
6条回答
  •  轮回少年
    2021-02-07 21:55

    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:

        @Override
        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 );
                    ps.executeBatch();
                }
                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).

提交回复
热议问题