我确定我的配置文件中没有相同的*.hbm.xml,也没有相同的类名,*.hbm.xml也是没有错误的,我用的是struts2+hibernate
%%%% Error Creating SessionFactory %%%%
org.hibernate.InvalidMappingException: Could not parse mapping document from resource ./com/shangjia/manage/vo/Syspar.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at com.shangjia.manage.util.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at com.shangjia.manage.biz.OperatorBiz.findAllOperator(OperatorBiz.java:25)
at com.shangjia.manage.action.SystemAction.login(SystemAction.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:184)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at rcept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.shangjia.manage.vo.Syspar
at org.hibernate.cfg.Mappings.addClass(Mappings.java:118)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:145)
at org.hibernate.cfg.Configuration.add(Configuration.java:669)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:504)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 121 more

解决方案 »

  1.   

    补充说明:上面的异常信息连报了两次,hibernate.cfg.xml配置文件如下:
    更为奇怪的是,我把Syspar.hbm.xml放到第一位,报异常就是uplicate class/entity mapping com.shangjia.manage.vo.Syspar,如果我把其他的*.hbm.xml放到第一位,就报uplicate class/entity mapping com.shangjia.manage.vo.*
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
              "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
              <!-- Generated by MyEclipse Hibernate Tools.                   -->
    <hibernate-configuration><session-factory> <property name="hibernate.connection.provider_class">
    org.hibernate.connection.ProxoolConnectionProvider
    </property>
    <property name="hibernate.proxool.pool_alias">DBPool</property>
    <property name="hibernate.proxool.xml">proxool.xml</property>
    <!-- 
    <property name="hbm2ddl.auto">update</property>
     -->
    <mapping resource="./com/shangjia/manage/vo/Syspar.hbm.xml" />
    <mapping resource="./com/shangjia/manage/vo/Housearea.hbm.xml" />
    <mapping resource="./com/shangjia/manage/vo/HouseInfo.hbm.xml" />
    <mapping resource="./com/shangjia/manage/vo/Operator.hbm.xml" />
    <mapping resource="./com/shangjia/manage/vo/LeaseInfo.hbm.xml" />

    <mapping resource="./com/shangjia/manage/vo/Role.hbm.xml" />
    <mapping resource="./com/shangjia/manage/vo/Limited.hbm.xml" />
     <!-- test
    <mapping resource="./com/shangjia/manage/vo/Course.hbm.xml" />
    <mapping resource="./com/shangjia/manage/vo/Teacher.hbm.xml" />
    -->
    <mapping resource="./com/shangjia/manage/vo/Room.hbm.xml" />
    <mapping resource="./com/shangjia/manage/vo/User.hbm.xml" />

    </session-factory></hibernate-configuration>
      

  2.   

    Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping com.shangjia.manage.vo.Syspar
    你看看映射 和数据库的字段 是不是数据类型不匹配
      

  3.   

    全贴出来啊,关键不是Syspar这个,我把那个类的配置文件放在第一位,就会报哪个类的错误,错误信息除了类名之外都一样。。   System.hbm.xml内容如下:<?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- 
        Mapping file autogenerated by MyEclipse Persistence Tools
    -->
    <hibernate-mapping>
        <class name="com.shangjia.manage.vo.Syspar" table="SYSPAR" schema="SHANGJIA">
            <id name="sid" type="java.lang.Long">
                <column name="SID" precision="22" scale="0" />
                <generator class="native"></generator>
            </id>
            <property name="parttype" type="java.lang.Long">
                <column name="PARTTYPE" precision="22" scale="0">
                    <comment>类型</comment>
                </column>
            </property>
            <property name="partid" type="java.lang.Long">
                <column name="PARTID" precision="22" scale="0">
                    <comment>类别</comment>
                </column>
            </property>
            <property name="partvalue" type="java.lang.String">
                <column name="PARTVALUE" length="10">
                    <comment>类别值</comment>
                </column>
            </property>
            <property name="re" type="java.lang.String">
                <column name="REMARK" length="20">
                    <comment>备注</comment>
                </column>
            </property>
        </class>
    </hibernate-mapping>
      

  4.   

    服务器,eclipse,全部重启,项目删掉,重新部署。试一试吧,多半没用。
      

  5.   

    你的路径怎么写成="./com/shangjia/manage/vo/Syspar.hbm.xml
    直接就写成com/shangjia/manage/vo/Syspar.hbm.xml
      

  6.   

    这个方法我已经试过了,一共就下面这几个文件,我注释掉Syspar.hbm.xml,系统就报Housearea错误,错误信息除了类名之外,其他的都一样,我注释掉前两个,就报第三个的错误,反正是哪个排在第一位就报哪个的错误,我在网上查了查,有的说在spring的项目中hibernate.cfg.xml被加载了两次,所以报这个错误,可是我没有用spring啊,难道我这个hibernate文件也被加载了两次?
    <mapping resource="com/shangjia/manage/vo/Syspar.hbm.xml" />
    <mapping resource="com/shangjia/manage/vo/Housearea.hbm.xml" />
    <mapping resource="com/shangjia/manage/vo/HouseInfo.hbm.xml" />
    <mapping resource="com/shangjia/manage/vo/Operator.hbm.xml" />
    <mapping resource="com/shangjia/manage/vo/LeaseInfo.hbm.xml" />
    <mapping resource="com/shangjia/manage/vo/Role.hbm.xml" />
    <mapping resource="com/shangjia/manage/vo/Limited.hbm.xml" />
    <mapping resource="com/shangjia/manage/vo/Room.hbm.xml" />
    <mapping resource="com/shangjia/manage/vo/User.hbm.xml" />
      

  7.   

    那lz配置hibernate相关的文件就hibernate.cfg.xml吗,如果其它开发人员在其它文件配置了诸如
           com/shangjia/manage/vo/*.hbm.xml
    的话,就加载2遍了。
      

  8.   

    楼主你这种配置是可以根据mapping文件生成表的对吧?那你把数据库表清空,然后把mapping的类都去掉,然后部署启动,看看数据库表有没有生成。
    如果生成,说明有其他地方已经mapping过了。
    如果没有生成,那可以确定项目中只有一个mapping的地方,但是加载了2遍。
      

  9.   

    你的代码里是否有sessionFactory = config.configure().buildSessionFactory这样的手动加载hibernate配置?如果你Spring已经加载了你的hibernate.cfg.xml而你又再次手工加载时,会报这个错
    ,检查com.shangjia.manage.util.HibernateSessionFactory这里的调用方式建议不用hibernate.cfg.xml来做hibernate的配置,而把这些配置全部交给spring的配置文件来做
      

  10.   

    是可以根据配置文件生成表,但是去掉mapping的类,怎么还能生成表呢?能详细说明吗?
      

  11.   

    我确实手动加载了hibernate配置,但是我没有用spring。
      

  12.   

    我记得hibernate会默认加载classpath下的hibernate.cfg.xml。(很久很久以前学的,忘了)。
    lz又手动加载了一遍,可能原因就在这儿了。
      

  13.   

    这什么东东,错误就在初始化SessionFactory的时候发生的,贴个源码给大家瞧瞧。
    com.shangjia.manage.util.HibernateSessionFactory,
    com.shangjia.manage.biz.OperatorBiz
      

  14.   

    HibernateSessionFactory 用于Creating SessionFactory 
    OperatorBiz是对员工信息进行操作的业务类,应该不是这的问题,问题出在 创建SessionFactory 工厂的时候,而且说原因是有两个实体映射
      

  15.   

    lz确定代码里手动加载hibernate配置的地方只有一处吗?
      

  16.   

    能告诉我,都什么地方可以加载hibernate配置吗?
      

  17.   

    加载hibernate配置的代码只能运行一次哦,第二次运行就报你的错了
      

  18.   

    应该是 *.hbm.xml的文件头写的有问题,我以前也遇到过,看上去写的没问题,但是就是报错,我是把其他项目里的*.hbm.xml的文件头粘过来的,就ok了,你试一下。
      

  19.   


    运行时报错,还以为是启动时报错呢!
    那你debug跟踪一下呗!
      

  20.   

    hibernate org.hibernate.DuplicateMappingExceptio这不是写的很明白了吗?重复的映射异常
      

  21.   

    不应该吧,*.hbm.xml都是eclipse自动生成的,而且我在网上也看到了说是头文件的问题可能会导致这个异常,但是我的头文件是没有问题的
      

  22.   

    问题貌似解决了,我在HibernateSessionFactory中写了静态块用于加载hibernate.cfg.xml和创建SessionFactory,可是不只为什么创建没有成功,当DAO getSession的时候,HibernateSessionFactory又重新加载了hibernate.cfg.xml并创建SessionFactory,但是只到加载了hibernate.cfg.xml就报错了。可为什么静态块中的SessionFactory没有创建成功呢?
    HibernateSessionFactory源码:
    package com.shangjia.manage.util;import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.cfg.Configuration;/**
     * Configures and provides access to Hibernate sessions, tied to the
     * current thread of execution.  Follows the Thread Local Session
     * pattern, see {@link http://hibernate.org/42.html }.
     */
    public class HibernateSessionFactory {    /** 
         * Location of hibernate.cfg.xml file.
         * Location should be on the classpath as Hibernate uses  
         * #resourceAsStream style lookup for its configuration file. 
         * The default classpath location of the hibernate config file is 
         * in the default package. Use #setConfigFile() to update 
         * the location of the configuration file for the current session.   
         */
        private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
    private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
        private  static Configuration configuration = new Configuration();    
        private static org.hibernate.SessionFactory sessionFactory;
        private static String configFile = CONFIG_FILE_LOCATION;// static {
    //     try {
    // configuration.configure(configFile);
    // sessionFactory = configuration.configure().buildSessionFactory();
    // } catch (Exception e) {
    // System.err
    // .println("%%%% Error Creating SessionFactory %%%%");
    // e.printStackTrace();
    // }
    //    }
        private HibernateSessionFactory() {
        }

    /**
         * Returns the ThreadLocal Session instance.  Lazy initialize
         * the <code>SessionFactory</code> if needed.
         *
         *  @return Session
         *  @throws HibernateException
         */
        public static Session getSession() throws HibernateException {
            Session session = (Session) threadLocal.get(); if (session == null || !session.isOpen()) {
    if (sessionFactory == null) {
    rebuildSessionFactory();
    }
    session = (sessionFactory != null) ? sessionFactory.openSession()
    : null;
    threadLocal.set(session);
    }        return session;
        } /**
         *  Rebuild hibernate session factory
         *
         */
    public static void rebuildSessionFactory() {
    try {
    configuration.configure(configFile);
    sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
    System.err
    .println("%%%% Error Creating SessionFactory %%%%");
    e.printStackTrace();
    }
    } /**
         *  Close the single hibernate session instance.
         *
         *  @throws HibernateException
         */
        public static void closeSession() throws HibernateException {
            Session session = (Session) threadLocal.get();
            threadLocal.set(null);        if (session != null) {
                session.close();
            }
        } /**
         *  return session factory
         *
         */
    public static org.hibernate.SessionFactory getSessionFactory() {
    return sessionFactory;
    } /**
         *  return session factory
         *
         * session factory will be rebuilded in the next call
         */
    public static void setConfigFile(String configFile) {
    HibernateSessionFactory.configFile = configFile;
    sessionFactory = null;
    } /**
         *  return hibernate configuration
         *
         */
    public static Configuration getConfiguration() {
    return configuration;
    }}
      

  23.   

    在一年后的今天,我也遇到了这个问题,你的问题和我遇到的应该是一样的问题,我是问我们项目组的高手解决的,看到这个帖子,很多人都没能给出答案,我给出下面的答案,不知准不准确,反正我是解决了的,参考参考
    背景:
    1、已经重复使用多种办法检查过配置文件 .hbm.xml 等,并未发现有重复的配置。
    2、部署方式:在 myeclipse 中使用 tomcat 部署项目
    3、已清空 tomcat 缓存
    4、已使用 myeclipse 重新编译,重新部署
    5、已关闭其他无关项目
    6、是在启动过程中报的错现在已经是确定没有重复映射,不是缓存影响的了,还是不能正确启动。最后经过多人尝试,找出了出错的原因:
    使用 tomcat 直接部署可能会出现错误,部署 myeclipse 中的项目可以按一下方式部署:
    在 %Tomcat_HOME%\conf\catalina\localhost 目录下新建以项目名为文件名的文件如:itsmsaas.xml
    ---------------------------------------------------------------------------------------
    <Context docBase="E:\\workspace\\saas\\web" path="/itsmsaas"  debug="0" privileged="true">
    </Context>
    ---------------------------------------------------------------------------------------
      

  24.   

    hibernate.cfg.xml里的<mapping resource="xxx/xxx/Syspar.hbm.xml"/>重复了??ctrl+F确认一下噜。。