异常:org.hibernate.MappingException:实体映射中的重复列

时间:2014-10-31 07:16:36

标签: java hibernate

UserDetails.java

@Entity
@Table(name="userdetails")
public class UserDetails {
//@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Id @Embedded
//@EmbeddedId
private int userId;
private String userName;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="street",column=@Column(name="home_street_name")),
@AttributeOverride(name="city",column=@Column(name="home_city_name")),
@AttributeOverride(name="state",column=@Column(name="HOME_STATE_NAME")),
@AttributeOverride(name="pincode",column=@Column(name="HOME_PINCODE"))
})
private Address homeAddress;
@Embedded
private Address officeAddress;

public Address getHomeAddress() {
    return homeAddress;
}
public void setHomeAddress(Address homeAddress) {
    this.homeAddress = homeAddress;
}
public Address getOfficeAddress() {
    return officeAddress;
}
public void setOfficeAddress(Address officeAddress) {
    this.officeAddress = officeAddress;
}
public int getUserId() {
    return userId;
}
public void setUserId(int userId) {
    this.userId = userId;
}
public String getUserName() {
    return userName;
}
public void setUserName(String userName) {
    this.userName = userName;
}

}

Address.java

@Embeddable
public class Address {
@Column(name="street_name")
private String Street;
@Column(name="city_name")
private String city;
@Column(name="state_name")
private String state;
@Column(name="pin_code")
private String pincode;
public String getStreet() {
    return Street;
}
public void setStreet(String street) {
    Street = street;
}
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 getPincode() {
    return pincode;
}
public void setPincode(String pincode) {
    this.pincode = pincode;
}

}

当我遇到异常时,

Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: embedded.UserDetails column: street_name (should be mapped with insert="false" update="false")

1 个答案:

答案 0 :(得分:1)

尝试更改Address类

中的以下行

private String Street;private String street;

哦,以下不适合我。我不得不在UserDetails类中更改以下内容

@Id @Embedded
//@EmbeddedId
private int userId;

到这个

@Id
//@EmbeddedId
private int userId;