Description:
|
My scenario is rather straightforward:
- I have an entity class which defines a single long PK column and has the @NaturalId(mutable = true) annotation on two other columns.
- I create more than one fresh instances of this entity and save them to the session using saveOrUpdate().
- Before flushing (flush mode = COMMIT), I set the columns for the natural IDs.
- Now Hibernate, instead of emitting a single SQL INSERT statement with the proper natural ID values for the entities it first INSERTs the records with the default values the entities have been saveOrUpdate()d with and then it fires a bunch of UPDATEs which update the natural ID columns to their proper values. This causes a unique constraint violation on the INSERTs.
Unfortunately, the underlying database I use (H2 1.3.170) does not support deferred constraint checking, so there's no other way than to remove the @NaturalId annotations from the business key of the entity.
Is this the intended behaviour?
- OR -
Shouldn't Hibernate recognize this situation and issue a single INSERT statement per entity object with the correct @NaturalId values? Given that the entities are in persistent state after saveOrUpdate() this would be the intuitive behaviour, IMHO.
|