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
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..
ReplyDeleteThat is an AWFUL solution and virtually unmaintainable.
ReplyDeleteAlso, 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