hibernate的配置文件报出异常。在线等 。org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: invalid configuration
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:217)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at com.hrfxb.persistence.util.SpringUtils.getBeanFactory(SpringUtils.java:16)
at com.hrfxb.persistence.service.DaoCheck.<init>(DaoCheck.java:14)
at com.hrfxb.persistence.test.DaoMethodTest.setUp(DaoMethodTest.java:20)
at junit.framework.TestCase.runBare(TestCase.java:128)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1487)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1443)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:603)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
... 28 more
Caused by: org.xml.sax.SAXParseException: The content of element type "mapping" must match "EMPTY".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
... 33 more

解决方案 »

  1.   

    org.xml.sax.SAXParseException: The content of element type "mapping" must match "EMPTY".
    你配置文件有问题,他不能解析
    你看看
      

  2.   

    我当然知道是有问题,可是问题在哪啊?以下是我的配置文件
    <?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.hrfxb.persistence.bean.TrdTranlist" table="TRD_TRANLIST"
    schema="HRMARDEV">
    <id name="id" type="int">
    <column name="ID" precision="22" scale="0" />
    <generator class="native" />
    </id>
    <property name="channelflowno" type="string">
    <column name="CHANNELFLOWNO" length="30" not-null="true" />
    </property>
    <property name="localflowno" type="string">
    <column name="LOCALFLOWNO" length="20" not-null="true" />
    </property>
    <property name="requestdate" type="string">
    <column name="REQUESTDATE" length="8" not-null="true" />
    </property>
    <property name="requesttime" type="string">
    <column name="REQUESTTIME" length="8" not-null="true" />
    </property>
    <property name="tradedate" type="string">
    <column name="TRADEDATE" length="8" not-null="true" />
    </property>
    <property name="tradetime" type="string">
    <column name="TRADETIME" length="8" not-null="true" />
    </property>
    <property name="tradecode" type="string">
    <column name="TRADECODE" length="5" not-null="true" />
    </property>
    <property name="requestorgan" type="string">
    <column name="REQUESTORGAN" length="4" not-null="true" />
    </property>
    <property name="channelno" type="string">
    <column name="CHANNELNO" length="4" not-null="true" />
    </property>
    <property name="tradecounter" type="string">
    <column name="TRADECOUNTER" length="15" not-null="true" />
    </property>
    <property name="terminalno" type="string">
    <column name="TERMINALNO" length="15" not-null="true" />
    </property>
    <property name="investiturecounter" type="string">
    <column name="INVESTITURECOUNTER" length="15" not-null="true" />
    </property>
    <property name="state" type="string">
    <column name="STATE" length="1" not-null="true" />
    </property>
    <property name="errcode" type="string">
    <column name="ERRCODE" length="5" not-null="true" />
    </property> <!-- 挂单表 -->
    <joined-subclass name="com.hrfxb.persistence.bean.TrdTranlistPreodrlist"
    table="Trd_Tranlist_Preodrlist">
    <key column="id" />
    <property name="channelflowno" type="string">
    <column name="CHANNELFLOWNO" length="30" not-null="true" />
    </property>
    <property name="localflowno" type="string">
    <column name="LOCALFLOWNO" length="20" not-null="true" />
    </property>
    <property name="requestdate" type="string">
    <column name="REQUESTDATE" length="8" not-null="true" />
    </property>
    <property name="preodrlistno" type="string">
    <column name="PREODRLISTNO" length="8" />
    </property>
    <property name="preodrlisttype" type="int">
    <column name="PREODRLISTTYPE" precision="1" scale="0" />
    </property>
    <property name="direction" type="int">
    <column name="DIRECTION" precision="1" scale="0" />
    </property>
    <property name="accountno" type="string">
    <column name="ACCOUNTNO" length="25" />
    </property>
    <property name="currencypaircode" type="string">
    <column name="CURRENCYPAIRCODE" length="4" />
    </property>
    <property name="handacount" type="java.math.BigDecimal">
    <column name="HANDACOUNT" precision="18" scale="2" />
    </property>
    <property name="proportion" type="java.math.BigDecimal">
    <column name="PROPORTION" precision="3" scale="2" />
    </property>
    <property name="margincurrency" type="string">
    <column name="MARGINCURRENCY" length="3" />
    </property>
    <property name="payoffprice" type="java.math.BigDecimal">
    <column name="PAYOFFPRICE" precision="18" scale="10" />
    </property>
    <property name="lossprice" type="java.math.BigDecimal">
    <column name="LOSSPRICE" precision="18" scale="10" />
    </property>
    <property name="endvaliddays" type="string">
    <column name="ENDVALIDDAYS" length="8" />
    </property>
    <property name="state" type="string">
    <column name="STATE" length="1" />
    </property>
    </joined-subclass> <!-- 签约信息表 -->
    <joined-subclass name="com.hrfxb.persistence.bean.TrdTranlistRegistration"
    table="Trd_Tranlist_Registration">
    <key column="id" />
    <property name="channelflowno" type="string">
    <column name="CHANNELFLOWNO" length="30" not-null="true" />
    </property>
    <property name="localflowno" type="string">
    <column name="LOCALFLOWNO" length="20" not-null="true" />
    </property>
    <property name="requestdate" type="string">
    <column name="REQUESTDATE" length="8" not-null="true" />
    </property>
    <property name="cardno" type="string">
    <column name="CARDNO" length="25" />
    </property>
    <property name="custno" type="string">
    <column name="CUSTNO" length="25" />
    </property>
    <property name="signuptype" type="int">
    <column name="SIGNUPTYPE" precision="1" scale="0" />
    </property>
    </joined-subclass>
    <!-- 转入转出表 -->
    <joined-subclass name="com.hrfxb.persistence.bean.TrdTranlistTransition"
    table="Trd_Tranlist_Transition">
    <key column="id" />
    <property name="channelflowno" type="string">
    <column name="CHANNELFLOWNO" length="30" not-null="true" />
    </property>
    <property name="localflowno" type="string">
    <column name="LOCALFLOWNO" length="20" not-null="true" />
    </property>
    <property name="requestdate" type="string">
    <column name="REQUESTDATE" length="8" not-null="true" />
    </property>
    <property name="accountno" type="string">
    <column name="ACCOUNTNO" length="25" />
    </property>
    <property name="tradeamount" type="java.math.BigDecimal">
    <column name="TRADEAMOUNT" precision="18" scale="2" />
    </property>
    <property name="chflag" type="int">
    <column name="CHFLAG" precision="1" scale="0" />
    </property>
    <property name="currency" type="string">
    <column name="CURRENCY" length="3" />
    </property>
    <property name="tradetype" type="int">
    <column name="TRADETYPE" precision="1" scale="0" />
    </property>
    <property name="hostbalance" type="java.math.BigDecimal">
    <column name="HOSTBALANCE" precision="18" scale="2" />
    </property>
    <property name="localbalance" type="java.math.BigDecimal">
    <column name="LOCALBALANCE" precision="18" scale="2" />
    </property>
    </joined-subclass>
    </class>
    </hibernate-mapping>