这里有一个链接指向
Hibernate Annotations documentation
这涵盖了你想要的大部分。结果映射将是沿着以下几条线的:
@Embeddable
public class ParentCompositeKey implements Serializable {
public long getFirstId() { ... }
public long getSecondId() { ... }
// setters
}
@Entity
public class Parent implements Serializable {
@Id
public ParentCompositeKey getId() { ... }
@OneToMany(cascade=CascadeType.ALL)
@JoinColumns ({
@JoinColumn(name="first_id"),
@JoinColumn(name="second_id")
})
public List getParentChildren() { ... }
// setters
}
这假设您没有联接表(从您的命名方案来看,是否这样做有点不清楚)。如果你这样做了,你只需要添加一个
@JoinTable
注释和移动
@JoinColumns
在它里面。