Im trying to map my entity with SQL Server Database. and getting exception as
Repeated column in mapping for entity: com.agency.Hotel column: ID (should be mapped with insert="false" update="false")
Following is my mapping file for Hotel
<?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>
and my Hotel Entity :
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()
+ "]";
}
}
<column name="ID" not-null="true" />should be something like<column name="locationID" not-null="true" />.<column name="ID" not-null="true" />signifies thatHotel.IDis also the foreign key column for the primary key column in theLocationtable. SinceHotel.IDis already defined as the primary key column for theHoteltable, this does not make sense and hence the error. If this were really the case, you won't have a<many-to-one/>but a<one-to-one/>relationship between the tables since they share the primary key. - manish