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
using JDK8
. I receive org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.poste.struts2.bean.CityDetails
. My 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>
Class code:
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
COLUMNS:
CITM_CITY_ID decimal(10,0)
CITM_CITY_NAME varchar(200
CITM_STATUS varchar(20)
Any idea? Thanks to
The problem is that you have a mapping for com.poste.struts2.bean.CityDetails
in your hibernate config file and also for annotation mapping in it.
Either remove the following line from hibernate.cfg.xml
<mapping class="com.poste.struts2.bean.CityDetails" />
or remove annotations in the class CityDetails
.
Such a duplicate can also be caused by renaming the mapped class and creating the application without destroying the old classes (for example, creating with Maven without running "mvn clean").
This is a very correct answer by Darshan , but this error can occur even if you mention the same class mapping by mistake. I got 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" />
as in the above mapping, I added Test1.hbm.xml again instead of Test3.hbm.xml
I had a problem and it caused some of the jars to be duplicated and I had to delete them and then clean up Jenkins (use the build tool I am using). Don't know the reason for these duplicated cans.
There are no two different hibernate mapping files that need to have the same properties or ID tags.
Maybe you just need to clean up your project and rebuild to fix the problem, as I am myself