hibernate dom4j exception

搭建ssh框架时出现错误:

INFO: HHH000221: Reading mappings from resource: com/linvan/pojo/User.hbm.xml
2013-6-29 21:38:47 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@78c6cbc: defining beans [sessionFactory,userDao,userService,userAction]; root of factory hierarchy
2013-6-29 21:38:47 org.springframework.web.context.ContextLoader initWebApplicationContext
严重: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.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:1486)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
	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:383)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
	at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
	at org.hibernate.cfg.Configuration.add(Configuration.java:478)
	at org.hibernate.cfg.Configuration.add(Configuration.java:474)
	at org.hibernate.cfg.Configuration.add(Configuration.java:647)
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:730)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2111)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2083)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2063)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2016)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1967)
	at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:282)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
	... 26 more
Caused by: org.dom4j.DocumentException: http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd%20 Nested exception: http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd%20
	at org.dom4j.io.SAXReader.read(SAXReader.java:484)
	at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
	... 38 more
2013-6-29 21:38:47 org.apache.catalina.core.StandardContext listenerStart
严重: 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/classes/applicationContext.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:1486)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:589)
	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:383)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.InvalidMappingException: Unable to read XML
	at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
	at org.hibernate.cfg.Configuration.add(Configuration.java:478)
	at org.hibernate.cfg.Configuration.add(Configuration.java:474)
	at org.hibernate.cfg.Configuration.add(Configuration.java:647)
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:730)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2111)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2083)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2063)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2016)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1967)
	at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:282)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
	... 26 more
Caused by: org.dom4j.DocumentException: http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd%20 Nested exception: http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd%20
	at org.dom4j.io.SAXReader.read(SAXReader.java:484)
	at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
	... 38 more
2013-6-29 21:38:47 com.sun.faces.config.ConfigureListener contextInitialized

出现错误的文件 User.hbm.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.linvan.pojo.User" table="user" catalog="yulinjingling">
        <id name="id" type="integer">
            <column name="id" />
            <generator class="native" />
        </id>
        <property name="username" type="string">
            <column name="username" length="40" not-null="true">
                <comment>用户名</comment>
            </column>
        </property>
        <property name="password" type="string">
            <column name="password" length="20" not-null="true">
                <comment>用户密码</comment>
            </column>
        </property>
        <property name="name" type="string">
            <column name="name" length="20">
                <comment>真实姓名</comment>
            </column>
        </property>
        <property name="sex" type="integer">
            <column name="sex">
                <comment>0:男,1:女,3:未知</comment>
            </column>
        </property>
        <property name="age" type="integer">
            <column name="age">
                <comment>年龄</comment>
            </column>
        </property>
        <property name="email" type="string">
            <column name="email" length="40" not-null="true">
                <comment>邮箱</comment>
            </column>
        </property>
    </class>
</hibernate-mapping>

 

错误原因,hibernate 的 dtd引入错误,需替换为:

<!DOCTYPE hibernate-mapping PUBLIC      
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

 

你可能感兴趣的:(Hibernate)