如果要使用多个相同的类。您必须对所有列执行操作。请尝试如下;Embedded
@AttributeOverrides
引用 JPA 属性覆盖
@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 集合表