-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mass insert hibernate objects (database restore)
PostPosted: Mon Sep 14, 2009 11:59 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.