Entity operations performed result in the following sequence of SQL statements being executed by Hibernate (according to the logs for org.hibernate.SQL and org.hibernate.type.descriptor.sql):
...
insert into fileContent (filename, originalFilename, id) values (<filenameA>, <originalFilenameA>, 15537);
insert into fileContent (filename, originalFilename, id) values (<filenameB>, <originalFilenameB>, 15538);
insert into fileContent (filename, originalFilename, id) values (<filenameC>, <originalFilenameC>, 15539);
...
update project set filea_id=15537, fileb_id=15538, filec_id=15539 where id=<projectId>;
The insert statements are executed without any errors.However, when committing the transaction, the update operation fails with an SQL exception:
org.hibernate.engine.jdbc.spi.SqlExceptionHelper[142] - ERROR: insert or update on table "project" violates foreign key constraint "fk__filea_id__filecontent"
Detail: Key (filea_id)=(15537) is not present in table "filecontent".
- PostgreSQL 14
- Postgresql JDBC 42.3.8
- Java OpenJDK 17
- Hibernate 5.6.14.Final
Anyone any idea, why this is happening? Am I missing something?