2015-11-18 210 views
0

我试图用SQL Server数据库映射我的实体。 并作为休眠映射:实体ID映射中的重复列

在实体映射重复柱得到异常:com.agency.Hotel柱:ID(应与插入物被映射=“假”更新=“假”)

以下是对于酒店我的映射文件

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

我检查了这个linkthis,仍然面临问题。

+0

''应该像''。 ''表示'Hotel.ID'也是'Location'表中主键列的外键列。由于'Hotel.ID'已经被定义为'Hotel'表的主键列,这是没有意义的,因此是错误的。如果情况确实如此,那么表格之间的关系就不会有'',因为它们共享主键。 – manish

回答

0

,当我每个表名的ID更改为TABLEID

例如,问题得到解决:

表名称:酒店

标识字段:HotelID

所有映射开始工作正常,因为有一些问题或混乱与休眠,它没有正确映射。