2017-10-06 14 views
0

複合キー(address1とaddress2)をマップキーとして与える方法。 @MapKey(name = "address1"、name = "address1")の代わりに@MapKey(name = "address1"、name = "address2"EclipseLink MapKey複合ユニークキー

@Entity 
public class Person { 
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "person") 
    @MapKey(name = "address1") 
    public Map<String, Address> getAddressMap() { 
     return addressMap; 
    } 

} 



@Entity 
public class Address { 
    private Integer id; 
    private String address1; 
    private String address2; 
    private Person person; 

} 

答えて

0

埋め込み型を使用してください。

address1address2のプロパティをカプセル化する埋め込み可能なクラス(PersonAddress)を作成します。その埋め込み可能なクラスをMapキーとして使用します。

@Entity 
public class Person { 
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "person") 
    public Map<PersonAddress, Address> getAddressMap() { 
     return addressMap; 
    } 

} 

@Entity 
public class Address { 
    private Integer id; 

    @Embedded 
    private PersonAddress; 

    @ManyToOne 
    private Person person; 
} 

@Embeddable 
public class PersonAddress { 
    private String address1; 
    private String address2; 
} 
関連する問題