gpt4 book ai didi

java - 线程 "main"中的异常 org.hibernate.MappingException : Repeated column in mapping for entity

转载 作者:行者123 更新时间:2023-12-04 04:46:56 26 4
gpt4 key购买 nike

我是 Hibernate 的初学者。

我收到此错误消息,但无法弄清楚出了什么问题:

Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: com.hibernate.aris.Subscribers column: city (should be mapped with insert="false" update="false")"



我在某处读到必须将 HBM​​ 文件中的属性设置为“反向”,但我还不知道这意味着什么。

任何建议将不胜感激?

称为地址的可嵌入类
@Embeddable
public class Address {
@Column (name = "STREET_NAME")
private String street;

@Column (name = "CITY_NAME")
private String city;

@Column (name = "POST_CODE")
private String postcode;

public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostcode() {
return postcode;
}
public void setPostcode(String postcode) {
this.postcode = postcode;
}
}

订户类
@Entity
@Table(name = "Subscriberstbl")
public class Subscribers {

private int subID;
private String firstname;
private String lastname;

@Embedded
@AttributeOverrides({
@AttributeOverride(name ="street", column = @Column(name="HOME_STREET_NAME")),
@AttributeOverride(name = "city", column = @Column(name="HOME_CITY_NAME")),
@AttributeOverride(name = "postcode", column = @Column(name="HOME_POST_CODE"))})
private Address homeaddress;

@Embedded
private Address officeaddress;

//Getters and Setters
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;
}

@Id
@GeneratedValue
public int getSubID() {
return subID;
}
public void setSubID(int subID) {
this.subID = subID;
}

public Address getOfficeAddress() {
return officeaddress;
}

public void setOfficeAddress(Address address) {
this.officeaddress = address;
}

public Address getHomeaddress() {
return homeaddress;
}

public void setHomeaddress(Address homeaddress) {
this.homeaddress = homeaddress;
}

}

最佳答案

您正在通过 FIELD(字段注释)和 PROPERTY(访问器注释)混合访问,PROPERTY 是赢家,所以 @AttributesOverride被忽略。
试试搬家 @Id @GeneratedValue从访问器到字段类。

关于java - 线程 "main"中的异常 org.hibernate.MappingException : Repeated column in mapping for entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18044795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com