Hibernate Mapping : Repeated column in mapping for entity ID

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()
                + "]";
    }
}

I have checked this link and this and still facing problem.

Answer

the issue is resolved when i change the ID of each table name to tableID

For example :

Table name : Hotel

Identity Field : HotelID

all the mapping started working fine as there was some problem or confusion with hibernate that it was not mapping correctly.

Leave a Reply

Your email address will not be published. Required fields are marked *