Hi,
In a one-to-many Object relationship, is it possible to have the many elements belong to different classes (which are mapped to different tables) ?
For eg. consider a class called "com.foo.Transaction" mapped to the table "Transaction". Assume that this entity has a collection attribute called "lineitems". Now, the line items are of different types "com.foo.Discount", "com.foo.Item", "com.foo.Tax" etc. They have different attributes and are stored in different tables in the database. But, they all have a common superclass "com.foo.LineItem".
In this scenario, is there a way to use a single "Set" to store all the line items, and have hibernate persist them to the respective tables at runtime. I'd like to avoid having different Sets for different line item types
package com.foo;
public class Transaction {
..
..
private Set lineItems = new HashSet();
..
..
void addLineItem(LineItem lineItem) {
lineItems.add(lineItem);
}
}
Thanks
Ratheesh
|