2

I need some help defining the following object hierarchy/ database relationship in Hibernate

From the object sense – Agent is inherited from Person and Agency is inherited from Organization. they are inherited from Party which can have multiple Addresses associated with it

alt text

The database consists of

Agent
-ID
-Name
-PartyID (references Party.ID)
Agency
-ID
-Name
-PartyID (references Party.ID)
Address
-AddrID
-PartyID (references Party.ID)
-Street
Party.
-PartyID
Community
  • 1
  • 1
shikarishambu
  • 2,219
  • 6
  • 35
  • 57
  • Can you sketch your class model with minimal pseudo code? From your description I am not sure how you want the relations. – Timo Westkämper May 25 '10 at 16:39
  • class Party { private BigInteger partyID...} class Organization extends Party { private....} class Person extends Party {...} class Agency extends Organization {...} class Agent extends Person {...} – shikarishambu May 25 '10 at 19:07
  • I've added a class diagram. If this diagram is inaccurate, feel free to fix it. By the way, do you use annotations or hbm.xml? – Pascal Thivent May 25 '10 at 20:45
  • The class diagram is correct. What tool did you use to create it? – shikarishambu May 26 '10 at 02:28

2 Answers2

4

this article could help you. includes src as well.

http://www.ibm.com/developerworks/java/library/j-hibernate/

community page

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html

Inv3r53
  • 2,929
  • 3
  • 25
  • 37
4

Something like the following could be a start

@Entity
public class Party {

  @Id
  private BigInteger partyID;

  private String name;

  @OneToMany(mappedBy="party")
  private Set<Address> addresses;

} 

@Entity
public class Organization extends Party {} 

@Entity
public class Person extends Party {} 

@Entity
public class Agency extends Organization {} 

@Entity
public class Agent extends Person {}

@Entity
public class Address{

  @Id
  private BigInteger addressID;

  @ManyToOne
  private Party party;

  private String street;
}
Timo Westkämper
  • 21,824
  • 5
  • 78
  • 111