获取org.hibernate.DuplicateMappingException:在hibernate3.0中复制类/实体映射

时间:2014-09-15 04:17:55

标签: hibernate tomcat java-8

我正在尝试使用hibernate3.0 struts2-core-2.1.6 Tomcat7.0.55JDK8使用org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.poste.struts2.bean.CityDetails运行网络应用。我得到了hibernate.cfg.xml。我的<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="connection.useUnicode">true</property> <property name="connection.characterEncoding">UTF-8</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/mydb</property> <property name="connection.username">uname</property> <property name="connection.password">pass</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="current_session_context_class">thread</property> <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property> <property name="hibernate.show_sql">true</property> <property name="format_sql">true</property> <property name="hibernate.use_sql_comments">true</property> <mapping class="com.poste.struts2.bean.CityDetails" /> </session-factory> </hibernate-configuration> 是:

package com.poste.struts2.bean;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name = "city_master")
public class CityDetails implements Serializable {
    private static final long serialVersionUID = 9149826260758390091L;
    private Long cityId;
    private String cityName;
    private String cityStatus;
    @Id
    @GenericGenerator(name="generator", strategy="increment")
    @GeneratedValue(generator="generator")
    @Column(name = "CITM_CITY_ID")
    public Long getCityId(){
        return this.cityId;
    }
    public void setCityId(Long cityId){
        this.cityId = cityId;
    }
    @Column(name = "CITM_CITY_NAME", columnDefinition = "nvarchar", length = 100)
    public String getCityName(){
        return this.cityName;
    }
    public void setCityName(String cityName){
        this.cityName = cityName;
    }
    @Column(name = "CITM_STATUS")
    public String getCityStatus() {
        return cityStatus;
    }
    public void setCityStatus(String cityStatus) {
        this.cityStatus = cityStatus;
    }
}

班级代码是:

activation-1.1.jar
antlr-2.7.6.jar
commons-beanutils.jar
commons-collections-3.1.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-lang-2.3.jar
commons-logging-1.0.4.jar
dom4j-1.6.1.jar
ejb3-persistence.jar
freemarker-2.3.16.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-validator.jar
hibernate3.jar
hsqldb.jar
httpclient-4.0.jar
itext-2.1.7.jar
java-mail-1.4.4.jar
JavaBridge.jar
javassist.jar
javax.persistence.jar
jcommon-1.0.16.jar
jfreechart-1.0.13.jar
json.jar
jta-1.1.jar
junit-3.8.1.jar
log4j-1.2.14.jar
mysql-connector-java-5.1.32.jar
ognl-2.6.11.jar
php-servlet.jar
poi-3.2-FINAL-20081019.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
slf4j-simple-1.5.8.jar
struts2-convention-plugin-2.1.6.jar
struts2-core-2.1.6.jar
struts2-dojo-plugin-2.2.3.jar
struts2-fullhibernatecore-plugin-1.4-GA.jar
struts2tutorial.jar
xwork-2.1.2.jar

我的WEB-INF / lib包含

CITM_CITY_ID    decimal(10,0)
CITM_CITY_NAME  varchar(200 
CITM_STATUS     varchar(20) 

COLUMNS是:

{{1}}

有什么想法吗?感谢

6 个答案:

答案 0 :(得分:10)

问题是你在hibernate配置文件中有com.poste.struts2.bean.CityDetails的映射,并且你在注释中有它的映射。

hibernate.cfg.xml

中删除以下行
 <mapping class="com.poste.struts2.bean.CityDetails" />

或删除CityDetails类中的注释。

答案 1 :(得分:8)

这样的重复也可能是由于重命名映射的类并构建应用程序而没有消除旧的类(例如,使用Maven构建而不运行&#34; mvn clean&#34;首先。)

答案 2 :(得分:2)

这是非常正确的答案 Darshan 但是,即使您错误地再次提到相同的类映射,也可能会出现此错误。我提到的时候收到了这个错误

<bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
        p:dataSource-ref="writeDataSource"
        p:mappingResources="com/my/test/Test1.hbm.xml,com/my/test/Test2.hbm.xml,com/my/test/Test1.hbm.xml" />


如上图所示,我再次将 Test1.hbm.xml 放入 Test3.hbm.xml

答案 3 :(得分:0)

我遇到了问题,这是因为有些罐子是重复的,我不得不将它们删除然后清理Jenkins(我使用的构建工具)。不知道这个重复的罐子的原因。

答案 4 :(得分:0)

没有两个不同的hibernate映射文件应该具有相同的属性或id标记。

答案 5 :(得分:0)

使用休眠5.4.11,在定义两个具有相同名称的JPQL查询后,我也收到此错误消息:

@NamedQuery(
        name = "Employee.getAll",
        query = "SELECT e FROM Employee e"
)
@NamedQuery(
        name = "Employee.findOlderThan",
        query = "SELECT e FROM Employee e WHERE e.age > :age"
)
@NamedQuery(
        name = "Employee.getAll",
        query = "SELECT e FROM Employee e"
)