The mapping shown below works perfectly in Hibernate 3.x.
@OneToOne(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }, optional = true)
@JoinColumn(name = "PAYLOAD_FILTER", unique = true)
private PayloadFilterExpression payloadFilter;
In Hibernate 5.x, the identical mapping causes the following error.
The table NMS_DAMPEN_CONFIG has a one-to-one connection with the table NMS_PAYLOAD_FILTER_EXPR. The index col value of NMS_PAYLOAD_FILTER_EXPR is used to populate column PAYLOAD_FILTER.
2023-04-10 01:35:02.749 ERROR [org.hibernate.engine.jdbc.batch.internal.BatchingBatch] HHH000315:
Exception executing batch [java.sql.BatchUpdateException: The statement was aborted because it would
have caused a duplicate key value in a unique or primary key constraint or unique index identified by
'UK_HJWHE1QKYLIS421SH7BTMYPH1' defined on 'NMS_DAMPEN_CONFIG'.], SQL: insert into NMS_DAMPEN_CONFIG
(UUID, VERSION, ENABLE, HR_INTERVAL, MIN_INTERVAL, PAYLOAD_FILTER, SEC_INTERVAL, ID) values (?, ?, ?, ?, ?, ?, ?, ?)
We tried modifying the annotations as indicated in this blog to check whether the inserts in the dependent table worked, but they didn’t. For example, try Cascade type “MERGE” as well as a combination of persist and merge.
We tried relaxing the unique key to test the inserts, and it worked well. However, there is worry that the updates will fail. As a result, we do not intend to alter the existing mappings.