-->
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: Help with mapping
PostPosted: Tue Jan 27, 2004 11:33 am 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
I have three main tables/objects, Customer, Order and Detail. There is a parent/child relationship between Order and Detail, and a many-to-one from Order to Customer.

I have a Status table/object that I needs to be able to reference any one of the three main tables. The obvious approach for me was to have a many-to-one within Status for each table. This works fine if I save a Status object that references all three, but if it references just one, I get an error that Hibernate couldn't insert null into XXX for each of the two undefined references (each link is defined as a foreign key).

Is there a standard pattern for implementing such a design?

I could implement a join table for Customer, Order and Detail, that contains a foreign key both objects (i.e. Customer and Status). This works ok for the Customer/Order/Detail end since they have a one-to-many relationship to Status anyways, but each Status object has a one-to-one relationship with one of the three main tables. And I can't figure out how to map this.

It *seems* like some form of joined-subclass may help, but I'm having trouble working throug that one.

Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 11:41 am 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
My thought on the joined-subclass is that I could create CustomerStatus, OrderStatus and DetailStatus classes as joined-sublasses of Status. Then each subclass table would hold the obligatory 'key' and a foreign key to the appropriate table.

Feedback?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 7:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No join table.
Hqve q look at <any/>
but <many-to-one/> should work. Does you DB get a not-null constaint on the FK columns?
Show mapping and DDL ?

_________________
Emmanuel


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.