Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting org.hibernate.DuplicateMappingException: Duplicate class/entity mapping in hibernate3.0

I am trying to run a webapp using hibernate3.0 with struts2-core-2.1.6 on Tomcat7.0.55 with JDK8. I am getting org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.poste.struts2.bean.CityDetails . My hibernate.cfg.xml is:

<?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>

The class code is:

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;
    }
}

My WEB-INF/lib contains

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

The COLUMNS are:

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

Any idea? Thanks

like image 880
Satya Avatar asked Sep 15 '14 04:09

Satya


3 Answers

The problem is you have mapping for com.poste.struts2.bean.CityDetails in hibernate config file, as well as you have mapping for it in annotations.

Either remove following line from hibernate.cfg.xml

 <mapping class="com.poste.struts2.bean.CityDetails" />

or remove annotations in CityDetails class.

like image 126
Darshan Lila Avatar answered Nov 01 '22 10:11

Darshan Lila


Such duplicate may also be caused by renaming the mapped class and building the application without wiping out the old classes (e.g. building with Maven without running "mvn clean" first.)

like image 42
cvnew Avatar answered Nov 01 '22 10:11

cvnew


That is very correct answer by Darshan but, this error may come even if you mention same class mapping again by mistake. I had received this error when i mentioned

<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" />


like in above mapping I have put Test1.hbm.xml again instead Test3.hbm.xml

like image 2
Kundan Atre Avatar answered Nov 01 '22 11:11

Kundan Atre