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?
|