Hello,
i try to import about 12116 objects which represent a cyclic graph of hibernate objets. This graph is coherent with respect to not-null, foreign key, etc constraints as it comes from a backup of an hibernante managed database.
If load that graph in memory and perform this code on an empty database:
Code:
for (Object o : backup.datas){
s.save(o);
}
tx.commit();
I get this error
Code:
Caused by: org.h2.jdbc.JdbcBatchUpdateException: Referential integrity constraint violation: FKE326B97EC91F9A74: PUBLIC.RH_PERSON FOREIGN KEY(HOME_ADDRESS) REFERENCES PUBLIC.RH_ADDRESS(ADDRESS_ID); SQL statement:
insert into RH_PERSON (LANGUAGE, NOTE, BIRTHDATE, BIRTHPLACE, FIRST_NAME, FORMULATION, GENDER, HOME_ADDRESS, LAST_NAME, NATIONALITY, ORG_ID, PICTURE, title, PERSON_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23002-110]
at org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1068)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:247)
because, somehow, Hibernate tries to reference a non existing address when saving employee. This caused by address not being saved first despite it being also in the batch). Please note that error occurs during the commit. This mean hibernate does know about that Address, as all calls to session.save(o) are done before the commit.
So what is the solution to save a graph of object in hibernate?