Hi all,
I have a domain object that is versioned (the current version is in one table and then each time it's changed, the last version is archived to a seperate table with the same structure). There are a number of tables that have a foreign key to the current version table. These tables also have an implicit foriegn key to the archive table.
I'm trying to figure out how to map this in Hibernate. So far I've found I can't map the related tables to the archived table because the foreign keys do match the primary key on the archive table.
Should I create a custom entity persister? If so, does anyone have tips or examples of how to accomplish this?
Or should I just manually load this? If so, how do I deal with other classes that are related to this class (thru many-to-one or collections)?
Thanks for any ideas.
Regards,
John
Here's a sketch of the problem:
Code:
// the versioned class that needs to work
// with both invoice_item and archive_invoice_item
class InvoiceItem {
String id;
Integer sequence;
List discounts;
}
// the discount class
class Discount {
Integer id,
Double percentage
}
table invoice_item {
id varchar(10) primary key,
seq int ## stores the current version number
);
table archive_invoice_item {
id varchar(10) primary key,
seq int primary key
);
table discount (
id int primary key,
percentage double
);
table invoice_item_discount (
invoice_item_id varchar(10) primary key,
discount_id int primary key,
foreign key fk_invoice_item (invoice_item_id) references invoice_item,
foreign key fk_discount (discount_id) references discount
);