Hibernate JPA: @OneToMany delete old, insert new without flush

Hibernate doesn’t know about, nor respect, all database constraints (e.g. MySQL unique constraints). It’s a known issue they don’t plan on addressing anytime soon.

Hibernate has a defined order for the way operations occur during a flush.

Entity deletions will always happen after inserts. The only answers I know about are to remove the constraint or add the additional flush.

EDIT: By the way, the reason for the defined order is that this is the only way to guarantee foreign key constraints (one of the constraints they DO care about) aren’t violated, even if the user does something out of order.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)