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: Howto relax generated constraints?
PostPosted: Wed Apr 07, 2010 7:28 am 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Hi,

I've two Entities, Item and Rack ... a Rack can have multiple Items, so I added a Collection to Rack:
Code:
public class Rack{
    @OneToMany(mappedBy="id")
    Collection<Item> items = new ArrayList<Item>();
}


However even that seems to generate constraints, and a simple insert into item isn't possible anymore:
Code:
INSERT INTO item VALUES(12, 'Hallo', 'Name', 10);
ERROR:  insert or update on table "item" violates foreign key constraint "fk2273135ddcd445"
DETAIL:  Key (id)=(12) is not present in table "rack".


Any idea whats the reason behind this?
(Note that I don't do manual SQL inserts, I've done it here, to get a cleaner error-msg)

Another problem I experience is that Item has an associated Placement entity:
Code:
//    @OneToOne
//    @JoinColumn(name="PLACEMENT_ID")
//    Placement placement;


However when placement=NULL because there has non been assigned so far, I also get an constraint voilation error.

Sorry for those noob-questions :/

Thanks, Clemens


Top
 Profile  
 
 Post subject: Re: Howto relax generated constraints?
PostPosted: Wed Apr 07, 2010 8:00 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
However even that seems to generate constraints


Hibernate per default does define a foreign key constraint on each foreign key in your mapping.
This is to guarantee referential integrity, and good so far.

That's what is strange in your case, is that in some way you are able to make hibernate
insert the new item-record before the new rack-record.
Usually data gets flushed in the right sequence.
Can you please post a snippet of your sourcecode which creates and persists the new item and rack instance?


Top
 Profile  
 
 Post subject: Re: Howto relax generated constraints?
PostPosted: Wed Apr 07, 2010 4:47 pm 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Sorry I completly messed the relation thing up. The way I tried to do this would have never worked.

Thanks for your patience and help!

- Clemens


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.