gpt4 book ai didi

hibernate - 获取 org.hibernate.DuplicateMappingException : Duplicate class/entity mapping in hibernate3. 0

转载 作者:行者123 更新时间:2023-11-28 21:48:29 25 4
gpt4 key购买 nike

我正在尝试使用 hibernate3.0struts2-core-2.1.6Tomcat7.0.55 上使用 运行一个 webapp >JDK8。我收到 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;
}
}

我的 WEB-INF/lib 包含

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

列是:

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

有什么想法吗?谢谢

最佳答案

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

要么从 hibernate.cfg.xml 中删除以下行

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

或删除 CityDetails 类中的注释。

关于hibernate - 获取 org.hibernate.DuplicateMappingException : Duplicate class/entity mapping in hibernate3. 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25840754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com