我正在嘗試創建一對Hibernate註釋類,以便從舊式系統中的一對錶中加載(只讀)。傳統系統使用一致的(如果有些過時的)方法來控制表格。是我試圖映射表如下:在休眠系統中使用舊式系統中的組合鍵連接表
Customer CustomerAddress
-------------------------- ----------------------------
customerNumber:string (pk) customerNumber:string (pk_1)
name:string sequenceNumber:int (pk_2)
street:string
postalCode:string
我已經通過創建CustomerAddress類這樣走近這個:
@Entity
@Table(name="CustomerAddress")
@IdClass(CustomerAddressKey.class)
public class CustomerAddress {
@Id
@AttributeOverrides({
@AttributeOverride(name = "customerNumber", column = @Column(name="customerNumber")),
@AttributeOverride(name = "sequenceNumber", column = @Column(name="sequenceNumber"))
})
private String customerNumber;
private int sequenceNumber;
private String name;
private String postalCode;
...
}
凡CustomerAddressKey類是一個簡單的序列化對象與兩個關鍵領域。客戶對象然後定義爲:
@Entity
@Table(name = "Customer")
public class Customer {
private String customerNumber;
private List<CustomerAddress> addresses = new ArrayList<CustomerAddress>();
private String name;
...
}
所以,我的問題是:我如何表達客戶表上的OneToMany關係?