如果您想使用多个相同Embedded
的类。你必须@AttributeOverrides
为所有列做。尝试如下;
参考JPA AttributeOverrides
@Embeddable
public class Address {
private String state;
@Column(name = "zip_code")
private String zip;
}
@Entity(name = "Employee")
public class Employee implements Serializable {
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "state", column = @Column(name = "province_1")),
@AttributeOverride(name = "zip", column = @Column(name = "postal_code_2"))
})
private Address address_1;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "state", column = @Column(name = "province_2")),
@AttributeOverride(name = "zip", column = @Column(name = "postal_code_2"))
})
private Address address_2;
}
我的建议是,如果Embedded
您的Entity
. 尝试使用@CollectionTable
.
@CollectionTable(name = "EMPLOYEE_ADDRESS", joinColumns = @JoinColumn(name = "ADDRESS_ID"))
private List<Address> addressList;
参考JPA 集合表