Inserts statements are executed in wrong order when hibernate.order_inserts=true is set in the configuration, leading to a foreign key violation. The problem occurs with bidirectional one-to-one mapping association. Probably it is the impact of the fix for https://hibernate.atlassian.net/browse/HHH-9864. A Minimal test case is appended: Phone: has a one-to-one-association to PhoneDetails with set propery "mappedBy" PhoneDetails: has a one-to-one-association to Phone If we persist Phone the error occurs. When order_inserts is set to false, the problem disappears. Steps to run the test case:
- unzip onetooneproblem.zip
- cd onetooneproblem
- mvn test
Received error: Hibernate: values next value for hibernate_sequence Hibernate: values next value for hibernate_sequence Hibernate: insert into PhoneDetails (phone_id, provider, technology, id) values (?, ?, ?, ?) sty 25, 2017 5:04:12 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release INFO: HHH000010: On release of batch it still contained JDBC statements sty 25, 2017 5:04:12 PM org.hibernate.engine.jdbc.batch.internal.BatchingBatch performExecution ERROR: HHH000315: Exception executing batch [java.sql.BatchUpdateException: INSERT on table 'PHONEDETAILS' caused a violation of foreign key constraint 'FKEOTUEV8JA8V0SDH29DYNQJ05P' for key (1). The statement has been rolled back.], SQL: insert into PhoneDetails (phone_id, provider, technology, id) values (?, ?, ?, ?) sty 25, 2017 5:04:12 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 20000, SQLState: 23503 sty 25, 2017 5:04:12 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: INSERT on table 'PHONEDETAILS' caused a violation of foreign key constraint 'FKEOTUEV8JA8V0SDH29DYNQJ05P' for key (1). The statement has been rolled back. sty 25, 2017 5:04:12 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure ERROR: HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute batch] |