-->
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: One-to-many relationship in a joined-subclass?
PostPosted: Wed Feb 11, 2004 1:42 pm 
Newbie

Joined: Wed Feb 11, 2004 1:02 pm
Posts: 2
This seems to be a basic question to me, but I read the reference documentation several times, the FAQs, and searched past topics. I've learned a lot, but I still haven't found what I'm looking for.

I have a base class A with a joined-subclass B. Class B has a one-to-many relationship with class C. The primary key in Class B (generated by class A and inherited by class B) is of course a foreign key in class C.

I am using a bi-directional relationship for the one-to-many Set, with cascade="all" and inverse="true".

When I attempt to insert data into all three tables in one transaction I get ORA-01400: cannot insert NULL into.... Hibernate generates three insert statement as expected and executes them in the correct order, but when the foreign key in class C is null. I expected this key to be what was ultimately generated and the primary key in class A. I do have the mapping for class C in a separate file than class A and B.

I would assume that a one-to-many relationship in a joined-subclass is supported and used by others.

Is there a "trick" for this type of relationship (yes, I've read the tips and tricks page as well) or some common mistakes that I can look for ? To me it seems pretty straight forward so I'm assuming that I'm just missing some small piece here.

_________________
Thanks for your help!

Jon


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 1:56 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You probably forgot to do
Code:
b.getCs().add(c);
c.setB(b); //this line


Have a look at http://www.hibernate.org/Documentation/InsideExplanationOfInverseTrue

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2004 2:13 pm 
Newbie

Joined: Wed Feb 11, 2004 1:02 pm
Posts: 2
That was the exact problem. I knew it was something small. Thanks for the link. I went back and looked at some of the other docs that I've read and it does show that in the examples; not sure how I missed that.

_________________
Thanks for your help!

Jon


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.