-->
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.  [ 3 posts ] 
Author Message
 Post subject: Saving child object before parent object (order problem)
PostPosted: Mon Apr 21, 2008 5:04 am 
Newbie

Joined: Fri Apr 04, 2008 8:16 am
Posts: 3
Hi everybody!

I have following problem: I first insert a child object (which row in the database references a parent row via foreign key) and after that I insert the parent object.

hibernate checks at the creation time if the parent object exists and returns an error. So far so good. We configured our Oracle database in a way that foreign key references will be checked at the commit time, thus an insert of a row with foreign key referencing a primary key, which does not exist at the insert time, will not indicate an error until DB commit.

In this way, we don't want to take care of the order, in which the objects are saved.

My question: can one disable the check that hibernate performs by insert of child objects?

thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 21, 2008 2:33 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Dimo,

I am not a Hibernate expert, and there might be some obscure configuration trick that allows you to do exactly what you want; but, in principle, it seems to me that parts of your question are contrary to the philosophy of Hibernate:

- you say that the DB does its own dependency checking "at commit time'. That suggests me that there is some commit command external to Hibernate.
Hibernate doesn't like that, since caching and determining when and what to commit accounts for a good deal of the framework's performance.

- You say that you don't want to be worried about the order in which objects are saved to the database. Well, if an object is defined, table-wise, as another object's parent, and that parent-child relationship is reflected in your Hibernate mappings, then Hibernate has no choice but to write those objects (whenever it deems necessary) in the right order. You can suspend referential integrity checking on an Oracle database with some Oracle code, but Hibernate will still execute the SQL commands in an order determined by the mapping files.

So, the short answer it: no, one cannot and should not void a parent-child check in Hibernate. If you don't want it to exist, simply don't specify on your mapping files, and ensure that integrity is maintained by some other (non-Hibernate) means.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 6:18 am 
Newbie

Joined: Fri Apr 04, 2008 8:16 am
Posts: 3
thanks for the answer. maybe you are right. there is no possibility to avoid that.


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

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.