Nara Simha (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63f1102...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDMzMzBiYWQ3...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16417?atlOrigin=eyJpIjoiNDMzMz...
) HHH-16417 (
https://hibernate.atlassian.net/browse/HHH-16417?atlOrigin=eyJpIjoiNDMzMz...
) Batch insert order messed by in hibernate5, worked in hib3 (
https://hibernate.atlassian.net/browse/HHH-16417?atlOrigin=eyJpIjoiNDMzMz...
)
Issue Type: Bug Affects Versions: 5.2.3 Assignee: Unassigned Components: hibernate-core,
hibernate-entitymanager, hibernate-orm-modules, metamodel Created: 02/Apr/2023 07:54 AM
Environment: OS: CentOS Linux release 7.9.2009
JDK: 11, Zulu
EJB 3.1, Hibernate 5.2.x,
WildFly Core 22.08.004
Database: postgreSQL as well as HSQLDB Labels: foreignkey Priority: Blocker Reporter: Nara
Simha (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63f1102...
)
Hibernate 5 does not maintain insertion order while updating batch records if there is a
circular depedency in entity tables.. The same code works well in Hibernate 3.x
Our models:
nms_dedup_conf has a column called corrincconfig which is dependent on “id” column of
nms_mgmtevent_config table (Many-to-One mapping)
This id of nms_mgmtevent_config table links with nms_incident_config table.
In turn, nms-incident_config has dedupconfiguration_id linking to the nms_dedup_conf’s id
column as depicted below:
This is in Dedup class
@ManyToOne(optional = true , fetch = FetchType.LAZY)
@JoinColumn(name = "CORRINCCONFIG" , nullable = true )
private MgmtEventConfig correlationIncidentConfig;
The issue is:
Even though the nms_dedup_config table has a foreign key relationship with
nms_mgmtevent_config table, hibernate tris to insert records into this table, instead of
the table its referencing, i.e., nms_mgmtevent_config table and fails with the following
error:
06:25:14.661 [main] ERROR org.hibernate.engine.jdbc.batch.internal.BatchingBatch -
HHH000315: Exception executing batch [java.sql.BatchUpdateException: Batch entry 3 insert
into NMS_DEDUP_CONF (UUID, VERSION, ENABLE, CRITERIA, CORRINCCONFIG, DEDUPCOUNT,
HR_INTERVAL, MIN_INTERVAL, SEC_INTERVAL, ID) values
('91c7b4a5-c02f-46b2-8824-5d09c14b12de', 0, '1', 4, 15930, 10, 4, 0, 0,
16293) was aborted. Call getNextException to see the cause.] , SQL: insert into
NMS_DEDUP_CONF (UUID, VERSION, ENABLE, CRITERIA, CORRINCCONFIG, DEDUPCOUNT, HR_INTERVAL,
MIN_INTERVAL, SEC_INTERVAL, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
06:25:14.672 [main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Batch entry 3
insert into NMS_DEDUP_CONF (UUID, VERSION, ENABLE, CRITERIA, CORRINCCONFIG, DEDUPCOUNT,
HR_INTERVAL, MIN_INTERVAL, SEC_INTERVAL, ID) values
('91c7b4a5-c02f-46b2-8824-5d09c14b12de', 0, '1', 4, 15930, 10, 4, 0, 0,
16293) was aborted. Call getNextException to see the cause.
06:25:14.673 [main] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: insert
or update on table "nms_dedup_conf" violates foreign key constraint
"fkm8ksah73i36pepu7rwidvsor1"
Detail: Key (corrincconfig)=(15930) is not present in table
"nms_mgmtevent_config".
(
https://hibernate.atlassian.net/browse/HHH-16417#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16417#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100221- sha1:57c27f3 )