|
I would like to be able to do something like @SQLInsert(check=ResultCheckStyle.NONE) without supplying the SQL statement for INSERTs.
In a PostgreSQL partitioned table, when inserting into the parent table people will typically set up a rule or trigger to redirect rows to the correct partition. Because no rows are actually inserted into the parent table, the database tells Hibernate 0 rows were updated. Hibernate doesn't like this - the default ExecuteUpdateResultCheckStyle is COUNT.
As a workaround I'm diving into the AbstractEntityPersister for the entity, finding the protected insertResultCheckStyles array, and setting all elements (normally just one) to ExecuteUpdateResultCheckStyle.NONE.
Other rejected workarounds include:
1. Use @SQLInsert on the entity and set check=ResultCheckStyle.NONE. This requires overriding the entire INSERT statement, and preserving the column order to match Hibernate's internal field order. I would really like to be able to do something like this without overriding the INSERT statement as it makes the entity hard to maintain. Plus I'm not sure where the Hibernate field order comes from, and if it can be relied upon to stay constant between machines, Hibernate versions, JVMs, etc.
2. Change the insert trigger to insert the row into the parent table, then delete the row afterward. This doubles the churn on the write-ahead logs - no good if you're inserting large bytea's.
3. Use an unconditional insert rule to insert the row into the current partition. PostgreSQL will return a proper row count only if this rule is the last one evaluated and has no conditions. This would prevent inserting data that doesn't belong in the "current" partition, and requires the rule to be updated every time the current partition changes. Example here: http://www.technology-ebay.de/the-teams/mobile-de/blog/postgresql-table-partitioning-hibernate.html
|