-->
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.  [ 1 post ] 
Author Message
 Post subject: [Advice] polymorphic mapping
PostPosted: Mon Mar 15, 2004 12:03 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:02 am
Posts: 46
Location: Kuala Lumpur, Malaysia
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,

Image

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]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.