Hibernate 映射:实体 ID 映射中的重复列
Hibernate Mapping : Repeated column in mapping for entity ID
我正在尝试将我的实体映射到 SQL 服务器数据库。
并获得异常
Repeated column in mapping for entity: com.agency.Hotel column: ID (should be mapped with insert="false" update="false")
以下是我的酒店映射文件
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.agency.Hotel" table="Hotels">
<meta attribute="class-description">
This class contains the employee detail.
</meta>
<id name="ID" type="int" column="ID">
<generator class="native"/>
</id>
<property name="name" column="Name" type="string"/>
<property name="star" column="Star" type="int"/>
<property name="pricePerWeek" column="pricePerWeek" type="double"/>
<many-to-one name="location" class="com.agency.Location" fetch="select">
<column name="ID" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
和我的酒店实体:
package com.agency;
public class Hotel {
private int iD = 0;
private int star = 0;
private String name = null;
private double pricePerWeek = 0.0;
private Location location = null;
private int locationID = 0;
public int getID() {
return iD;
}
public void setID(int newID) {
iD = newID;
}
public int getStar() {
return star;
}
public void setStar(int newStar) {
star = newStar;
}
public String getName() {
return name;
}
public void setName(String newName) {
name = newName;
}
public double getPricePerWeek() {
return pricePerWeek;
}
public void setPricePerWeek(double newPricePerWeek) {
pricePerWeek = newPricePerWeek;
}
public Location getLocation() {
return location;
}
public void setLocation(Location newLocation) {
location = newLocation;
}
public int getLocationID() {
return locationID;
}
public void setLocationID(int newLocationID) {
locationID = newLocationID;
}
@Override
public String toString() {
return "Hotel " + " [iD: " + getID() + "]" + " [star: " + getStar()
+ "]" + " [name: " + getName() + "]" + " [pricePerWeek: "
+ getPricePerWeek() + "]" + " [locationID: " + getLocationID()
+ "]";
}
}
我已经检查过这个 link and this 但问题仍然存在。
当我将每个 table 名称的 ID 更改为 tableID
时,问题得到解决
例如:
Table 名称:酒店
身份字段:酒店 ID
所有映射都开始正常工作,因为存在一些问题或与 hibernate 混淆,它没有正确映射。
我正在尝试将我的实体映射到 SQL 服务器数据库。 并获得异常
Repeated column in mapping for entity: com.agency.Hotel column: ID (should be mapped with insert="false" update="false")
以下是我的酒店映射文件
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.agency.Hotel" table="Hotels">
<meta attribute="class-description">
This class contains the employee detail.
</meta>
<id name="ID" type="int" column="ID">
<generator class="native"/>
</id>
<property name="name" column="Name" type="string"/>
<property name="star" column="Star" type="int"/>
<property name="pricePerWeek" column="pricePerWeek" type="double"/>
<many-to-one name="location" class="com.agency.Location" fetch="select">
<column name="ID" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
和我的酒店实体:
package com.agency;
public class Hotel {
private int iD = 0;
private int star = 0;
private String name = null;
private double pricePerWeek = 0.0;
private Location location = null;
private int locationID = 0;
public int getID() {
return iD;
}
public void setID(int newID) {
iD = newID;
}
public int getStar() {
return star;
}
public void setStar(int newStar) {
star = newStar;
}
public String getName() {
return name;
}
public void setName(String newName) {
name = newName;
}
public double getPricePerWeek() {
return pricePerWeek;
}
public void setPricePerWeek(double newPricePerWeek) {
pricePerWeek = newPricePerWeek;
}
public Location getLocation() {
return location;
}
public void setLocation(Location newLocation) {
location = newLocation;
}
public int getLocationID() {
return locationID;
}
public void setLocationID(int newLocationID) {
locationID = newLocationID;
}
@Override
public String toString() {
return "Hotel " + " [iD: " + getID() + "]" + " [star: " + getStar()
+ "]" + " [name: " + getName() + "]" + " [pricePerWeek: "
+ getPricePerWeek() + "]" + " [locationID: " + getLocationID()
+ "]";
}
}
我已经检查过这个 link and this 但问题仍然存在。
当我将每个 table 名称的 ID 更改为 tableID
时,问题得到解决例如:
Table 名称:酒店
身份字段:酒店 ID
所有映射都开始正常工作,因为存在一些问题或与 hibernate 混淆,它没有正确映射。