I created a project which showcases the issue: https://github.com/schnesim/SpringTest As of right now the project uses Spring Boot 2.1.7 (which in turn uses Hibernate 5.3.x). When you run the project and call http://localhost:8080/save two entities get saved in h2 database. When the Spring version is changed to 2.2.2 (which uses Hibernate 5.4.x) the save operation fails with an org.hibernate.exception.ConstraintViolationException. The SQL log of Spring 2.1.7 shows these actions: {{2020-01-12 15:48:19.936 DEBUG 83902 — [nio-8080-exec-1] org.hibernate.SQL : select table1x0_.cryptid as cryptid1_0_1_, table2x1_.fk_cryptid as fk_crypt1_1_0_, table2x1_.pers_id as pers_id2_1_0_ from table1 table1x0_ left outer join table2 table2x1_ on table1x0_.cryptid=table2x1_.fk_cryptid where table1x0_.cryptid=? 2020-01-12 15:48:19.950 DEBUG 83902 — [nio-8080-exec-1] org.hibernate.SQL : select table2x0_.fk_cryptid as fk_crypt1_1_0_, table2x0_.pers_id as pers_id2_1_0_ from table2 table2x0_ where table2x0_.fk_cryptid=? 2020-01-12 15:48:19.955 DEBUG 83902 — [nio-8080-exec-1] org.hibernate.SQL : insert into table1 (cryptid) values 2020-01-12 15:48:19.957 DEBUG 83902 — [nio-8080-exec-1] org.hibernate.SQL : insert into table2 (pers_id, fk_cryptid) values (?, ?) }} With Spring Boot 2.2.x (Hibernate 5.4.x) the following is output: {{2020-01-12 15:49:48.309 DEBUG 84067 — [nio-8080-exec-1] org.hibernate.SQL : select table1x0_.cryptid as cryptid1_0_0_ from table1 table1x0_ where table1x0_.cryptid=? 2020-01-12 15:49:48.315 DEBUG 84067 — [nio-8080-exec-1] org.hibernate.SQL : select table2x0_.fk_cryptid as fk_crypt1_1_0_, table2x0_.pers_id as pers_id2_1_0_ from table2 table2x0_ where table2x0_.fk_cryptid=? 2020-01-12 15:49:48.329 DEBUG 84067 — [nio-8080-exec-1] org.hibernate.SQL : insert into table2 (pers_id, fk_cryptid) values (?, ?) 2020-01-12 15:49:48.332 WARN 84067 — [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 23506, SQLState: 23506 2020-01-12 15:49:48.332 ERROR 84067 — [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : Referential integrity constraint violation: "FK_CRYPTID: PUBLIC.TABLE2 FOREIGN KEY(FK_CRYPTID) REFERENCES PUBLIC.TABLE1(CRYPTID) ('ee855cd9-493a-440a-950a-17b7c130fc19')"; SQL statement: insert into table2 (pers_id, fk_cryptid) values (?, ?) [23506-200]}} The order of the inserts has been changed which consequently causes the exception. |