hibernate映射和spring'sessionFactory'有什么问题?

时间:2016-05-03 01:38:26

标签: spring hibernate

我做了一个字段更改并添加了一个新的xml映射,然后spring sessionFactory将无法正常工作,我无法分辨出问题所在:

    SEVERE: Exception sending context initialized event to listener instance  of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-security.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
    at  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
    at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)
    at org.hibernate.cfg.Configuration.add(Configuration.java:510)
    at org.hibernate.cfg.Configuration.add(Configuration.java:506)
    at org.hibernate.cfg.Configuration.add(Configuration.java:686)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:771)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2314)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2280)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2260)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2213)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2164)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:645)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
    ... 22 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 221; columnNumber: 11; The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:232)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:173)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:362)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:296)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:1953)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:878)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.handleEndElement(XMLDocumentFragmentScannerImpl.java:1144)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:987)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1445)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:333)
    at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:524)
    at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:580)
    at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1169)
    at org.dom4j.io.SAXReader.read(SAXReader.java:465)
    at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:75)
    ... 35 more

May 02, 2016 6:09:31 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
18:09:31,651 ERROR ContextLoader:319 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-security.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
    at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)
    at org.hibernate.cfg.Configuration.add(Configuration.java:510)
    at org.hibernate.cfg.Configuration.add(Configuration.java:506)
    at org.hibernate.cfg.Configuration.add(Configuration.java:686)
    at org.hibernate.cfg.Configuration.addResource(Configuration.java:771)
    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2314)
    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2280)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2260)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2213)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2164)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:645)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
    ... 22 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 221; columnNumber: 11; The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)".
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:232)
    at org.apache.xerces.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:173)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:362)
    at org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:296)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:1953)
    at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:878)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.handleEndElement(XMLDocumentFragmentScannerImpl.java:1144)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:987)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1445)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:333)
    at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:524)
    at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:580)
    at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1169)
    at org.dom4j.io.SAXReader.read(SAXReader.java:465)
    at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:75)
    ... 35 more

这是我的sessionFactory:

<beans:bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <beans:property name="dataSource" ref="dataSource" />       
    <beans:property name="configLocation">
        <beans:value>/WEB-INF/classes/hibernate.cfg.xml</beans:value>               
    </beans:property>
</beans:bean>

<beans:bean id="transactionManager" 
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>

<!-- may only need tx:annotation, not the above -->
    <tx:annotation-driven/> 

这是Hibernate.config.xml:

 <session-factory>
 ...
 <!-- mapping files -->
    <mapping resource="com/mycom/advertiser/bean/Customer.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/Advertiser.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/Campaign.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/Container.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/ProductDetail.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/CampaignContainer.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/CampaignContainerCateg.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/CampaignStatusCode.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/CampaignContainerPrice.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/CampaignContainerKeyword.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/CampaignContainerGeography.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/StatusCode.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/CampaignParameter.hbm.xml"/>
    <!--mapping resource="com/mmycom/advertiser/bean/CapProvider.hbm.xml"/-->
    <mapping resource="com/mycom/advertiser/bean/PhoneCall.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/bean/PhoneCallNote.hbm.xml"/>
    <!-- mapping resource="com/mmerchant/bean/CategGeoPrice.hbm.xml"/-->
    <mapping resource="com/mbilling/bean/TransactionReason.hbm.xml"/>
    <mapping resource="com/mbilling/bean/PaymentMethod.hbm.xml"/>
    <mapping resource="com/mbilling/bean/AllTransaction.hbm.xml"/> 
    <mapping resource="com/mbilling/bean/TransactionDetail.hbm.xml"/>
    <mapping resource="com/mbilling/bean/AccountingPeriod.hbm.xml"/>  
    <mapping resource="com/mbilling/bean/TransactionResponse.hbm.xml"/>  
    <mapping resource="com/mbilling/bean/EmailInvoicePdfStatus.hbm.xml"/> 

    <mapping resource="com/msem/bean/AdSem.hbm.xml"/>
    <mapping resource="com/msales/bean/AccountRep.hbm.xml"/>
    <mapping resource="com/msales/bean/SalesDivision.hbm.xml"/>
    <mapping resource="mycom/core/user/bean/User.hbm.xml"/>                            
    <mapping resource="mycom/external/bean/ExternalUser.hbm.xml"/>
    <mapping resource="mycom/core/geography/bean/Geography.hbm.xml"/>
    <mapping resource="mycom/core/content/bean/Content.hbm.xml"/>
    <mapping resource="mycom/core/content/bean/Ticket.hbm.xml"/>
    <mapping resource="mycom/core/listing/bean/Listing.hbm.xml"/>
    <mapping resource="mycom/core/listing/bean/Address.hbm.xml"/>
    <mapping resource="mycom/core/content/bean/Menu.hbm.xml"/>
    <mapping resource="mycom/core/term/bean/Categ.hbm.xml"/>
    <mapping resource="mycom/core/term/bean/CategGroup.hbm.xml"/>
    <mapping resource="mycom/core/term/bean/Keyphrase.hbm.xml"/>
    <mapping resource="mycom/core/user/bean/LoginTrail.hbm.xml"/>
    <mapping resource="mycom/core/user/bean/Role.hbm.xml"/>
    <mapping resource="mycom/core/user/bean/Permission.hbm.xml"/>
    <mapping resource="mycom/core/content/bean/Ad.hbm.xml"/>  
    <mapping resource="mycom/core/content/bean/Coupon.hbm.xml"/> 
    <mapping resource="mycom/customer/CustomerProperty.hbm.xml"/>
    <mapping resource="mycom/core/geography/bean/USRegion.hbm.xml"/>
    <mapping resource="mycom/core/content/bean/UserComment.hbm.xml"/>
    <!--mapping resource="mycom/core/user/bean/LoginHistory.hbm.xml"/--> 
    <!--mapping resource="mycom/core/content/bean/UserSubscription.hbm.xml"/-->  
    <mapping resource="mycom/core/content/bean/Subscription.hbm.xml"/>                                  
    <mapping resource="com/mycom/advertiser/ext/bean/TrackedEmail.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/ext/bean/TrackedPhone.hbm.xml"/>
    <mapping resource="com/mycom/advertiser/ext/bean/VideoShoot.hbm.xml"/>
    <mapping resource="com/mrevenue/bean/Budget.hbm.xml"/>
    <mapping resource="com/mrevenue/bean/BudgetAllocation.hbm.xml"/>
    <mapping resource="com/mrevenue/bean/RateCard.hbm.xml"/>

    <mapping resource="com/mycom/publisher/bean/Publisher.hbm.xml"/>
    <mapping resource="com/mycom/publisher/bean/Rank.hbm.xml"/>  
    <mapping resource="com/mycom/report/bean/DailyConnection.hbm.xml"/>  
</session-factory>

0 个答案:

没有答案