Greetings,
I'm looking for some advice regarding a mapping problem. This is more of a design issue.
Problem domain: I have 4 main entities, let's call them A, B, C & D. They have totally different fields except for the fact that their
id is auto-generated. I'm creating a new entity called "Exchange" to model workflow among these four entities. For example, A might send an purchase order to B; B sends an invoice to A and so on. Exchange will contain the relevant metadata about the exchanges between all these parties:
e.g. date, comment, reference number, fromParty, toParty
The fromParty and toParty fields should obviously need to be polymorphic. i.e. they may contain ids from A, B, C & D. My first stab at this is to create an abstract class called
Party, which is the superclass for the four entities. Thus,
Code:
/**
* @hibernate.class
* table = "t_exchanges"
*/
public class Exchange extends Saveable {
Party sender;
Party recipient;
Date when;
String comment;
/**
* @hibernate.many-to-one
* column = "id"
* class = "foo.Party"
*/
public Party getSender() {
...
}
---o<--- snip ---
}
Q1) Is it ok to make class
Party abstract ?
Q2) As a corollary to Q1, is it advisable to make
Party an interface ?
Q3) Is the mapping above correct for the
sender and
receipient fields.
Regards,
alistair[/img]