-->
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.  [ 2 posts ] 
Author Message
 Post subject: not null foreign key column
PostPosted: Thu Aug 09, 2007 10:59 pm 
Newbie

Joined: Tue Mar 27, 2007 11:34 pm
Posts: 13
Hi all, I had a problem about the mapping the one-to-many collection to NHibernate:

Suppose I had 2 entity A and B:

create table A (id int primary key);
create table B (id int primary key, aid int not null reference A);


A.hbm.xml
Code:
<set name="Bs" lazy="true" cascade="save-update" inverse="false">
  <key column="aid"/>
  <one-to-many class="A, test"/>
</set>


B.hbm.xml
Code:
No A related mapping in B, seems it is one way association


When I insert A, it will save B also, but I found that aid will not inserted to B. So it cannot be inserted, No this kind of problem when using inverse="true".

Did anyone know how to solve this problem?[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 10, 2007 10:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
http://www.hibernate.org/hib_docs/nhibe ... -onetomany

Quote:
Very Important Note: If the <key> column of a <one-to-many> association is declared NOT NULL, NHibernate may cause constraint violations when it creates or updates the association. To prevent this problem, you must use a bidirectional association with the many valued end (the set or bag) marked as inverse="true". See the discussion of bidirectional associations later in this chapter.

_________________
Karl Chu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.