Thursday, June 9, 2011

Hibernate + PostgreSQL + Table Partitioning

Problem: using Hibernate to insert a new entry into a partitioned table on PostgreSQL would get the following exception:


2011-06-08 16:37:07,725 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] -

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1


Solution:

use a @SQLInsert(sql = "insert into table (col_1, col_2) values (?, ?)", check=ResultCheckStyle.NONE)


more solutions provided here:

http://www.redhat.com/f/pdf/jbw/jmlodgenski_940_scaling_hibernate.pdf

2 comments:

  1. Thanks. It would be great if one could disable the result checks globally, since I hate to maintain the SQL statements in Strings.. that basically why i use hibernate..

    ReplyDelete
  2. That is an AWFUL solution and virtually unmaintainable.

    Also, this seems to happen for us when there's a trigger associated with the table as well.

    There's a way to set an override on the batch processing, apparently: http://stackoverflow.com/questions/83093/hibernate-insert-batch-with-postgresql

    ReplyDelete