Я использую в своем проекте JPA встроенные объекты.
У меня есть этот встраиваемый класс
@Embeddable
public class Address {
private String addressLine1;
private String addressLine2;
private String city;
private String state;
private String zipCode;
public String getAddressLine1() {
return addressLine1;
}
public void setAddressLine1(String addressLine1) {
this.addressLine1 = addressLine1;
}
public String getAddressLine2() {
return addressLine2;
}
public void setAddressLine2(String addressLine2) {
this.addressLine2 = addressLine2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZipCode() {
return zipCode;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
}
И я встраиваю этот класс сюда
@Entity
public class Customer implements
DomainObject{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Version
private Integer version;
private String firstName;
private String lastName;
private String email;
private String phoneNumber;
@Embedded
private Address billingAddress;
@Embedded
private Address shippingAddress;
@OneToOne
private User user;
@Override
public Integer getId() {
return id;
}
@Override
public void setId(Integer id) {
this.id = id;
}
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Address getBillingAddress() {
return billingAddress;
}
public void setBillingAddress(Address billingAddress) {
this.billingAddress = billingAddress;
}
public Address getShippingAddress() {
return shippingAddress;
}
public void setShippingAddress(Address shippingAddress) {
this.shippingAddress = shippingAddress;
}
}
После запуска проекта я это ошибка
Повторяющийся столбец в картографической сущности:
theo.tziomakas.udemy.domain.Colmer столбец: billing_address_line1 (должен отображаться с помощью insert = "false" update = "false"
Вы можете клонировать мой проект , если хотите, и проверить это самостоятельно.
Я также попробовал этот ответ, но ничего не получил.
UPDATE
Я решил эту ошибку с помощью аннотации AttributeOverride.
@Embedded
@AttributeOverrides({
@AttributeOverride( name = "addressLine1",
column = @Column(name = "billing_address_line1")
),
@AttributeOverride( name = "addressLine2",
column = @Column(name = "billing_address_line2")
),
@AttributeOverride( name = "city",
column = @Column(name = "billing_city")
),
@AttributeOverride( name = "state",
column = @Column(name = "billing_state")
),
@AttributeOverride( name = "zipCode",
column = @Column(name = "billing_zip_code")
)
})
private Address billingAddress;
@Embedded
@AttributeOverrides({
@AttributeOverride( name = "addressLine1",
column = @Column(name = "shipping_address_line1")
),
@AttributeOverride( name = "addressLine2",
column = @Column(name = "shipping_address_line2")
),
@AttributeOverride( name = "city",
column = @Column(name = "shipping_city")
),
@AttributeOverride( name = "state",
column = @Column(name = "shipping_state")
),
@AttributeOverride( name = "zipCode",
column = @Column(name = "shipping_zip_code")
)
})
private Address shippingAddress;