我想创建一个具有两个电话号码的类Exporter:固定电话和移动电话。
知道电话号码是由国家代码和号码组成的,我创建了一个Embeddable
类:
@Embeddable
public class EmbeddablePhone implements Serializable {
private static final long serialVersionUID = -6573789138766984739L;
@Column(name = "COUNTRY_COD")
private String countryCode;
@Column(name = "PHONE_NUMBER")
private String number;
public EmbeddablePhone () {
}
//getters and setters
}
如何在类Exporter中使用此类来引用固定电话和移动电话:
public class Exporter implements Serializable{
.....
......
@Embedded
private EmbeddablePhone landLine;
@Embedded
private EmbeddablePhone moblePhone;
public Exporter () {
}
//getters and setters
}
答案 0 :(得分:3)
使用@AttributeOverride
注释。
@Embedded
@AttributeOverrides({
@AttributeOverride(name="countryCode", column=@Column(name="MOB_COUNTRY_COD")),
@AttributeOverride(name="number", column=@Column(name="MOB_NUMBER"))})
private EmbeddablePhone moblePhone;