我需要一些帮助来定义Hibernate中的以下对象层次结构/数据库关系
从对象意义上来说 - Agent继承自Person,而Agency则继承自Organization。它们是从Party继承的,可以有多个与之关联的地址
数据库由
Agent -ID -Name -PartyID (references Party.ID)
Agency -ID -Name -PartyID (references Party.ID)
Address -AddrID -PartyID (references Party.ID) -Street
Party. -PartyID
答案 0 :(得分:4)
这篇文章可以帮到你。包括src。
http://www.ibm.com/developerworks/java/library/j-hibernate/
社区页面
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/inheritance.html
答案 1 :(得分:4)
以下内容可能是一个开始
@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;
}