在myeclipse反向工程数据库中创建SessionFactory Hibernate时出错

在myeclipse反向工程数据库中创建SessionFactory Hibernate时出错,hibernate,jakarta-ee,hibernate-mapping,object-relational-model,Hibernate,Jakarta Ee,Hibernate Mapping,Object Relational Model,我正在myeclipse中学习冬眠。我尝试对mysql表进行反向工程,并遵循官方的myeclipse教程。所有xml文件都已生成,但编写简单的测试程序时会出现以下错误: 17-dic-2012 19.18.57 org.hibernate.annotations.common.Version 信息:HCANN000001:Hibernate Commons注释{4.0.1.Final} 17-dic-2012 19.18.57 org.hibernate.Version日志版本 信息:hh00

我正在myeclipse中学习冬眠。我尝试对mysql表进行反向工程,并遵循官方的myeclipse教程。所有xml文件都已生成,但编写简单的测试程序时会出现以下错误:

17-dic-2012 19.18.57 org.hibernate.annotations.common.Version
信息:HCANN000001:Hibernate Commons注释{4.0.1.Final}
17-dic-2012 19.18.57 org.hibernate.Version日志版本
信息:hh000412:Hibernate核心{4.1.4.Final}
17-dic-2012 19.18.57 org.hibernate.cfg.Environment
信息:HH000206:找不到hibernate.properties
17-dic-2012 19.18.57 org.hibernate.cfg.Environment buildBytecodeProvider
信息:HH000021:字节码提供程序名称:javassist
17-dic-2012 19.18.57 org.hibernate.cfg.Configuration
信息:HH000043:从资源配置:/hibernate.cfg.xml
17-dic-2012 19.18.57 org.hibernate.cfg.Configuration getConfigurationInputStream
信息:hh000040:配置资源:/hibernate.cfg.xml
17-dic-2012 19.18.57 org.hibernate.cfg.Configuration addResource
信息:hh000221:正在从资源读取映射:sor/hibernate/Hitest.hbm.xml
%%%%创建SessionFactory%%%时出错
org.hibernate.InvalidMappingException:无法读取XML
位于org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
位于org.hibernate.cfg.Configuration.add(Configuration.java:478)
位于org.hibernate.cfg.Configuration.add(Configuration.java:474)
在org.hibernate.cfg.Configuration.add上(Configuration.java:647)
位于org.hibernate.cfg.Configuration.addResource(Configuration.java:730)
位于org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2109)
位于org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2081)
位于org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2061)
位于org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2014)
位于org.hibernate.cfg.Configuration.configure(Configuration.java:1929)
位于org.hibernate.cfg.Configuration.configure(Configuration.java:1908)
位于sor.hibernate.HibernateSessionFactory。(HibernateSessionFactory.java:32)
在sor.hibernate.BaseHibernateDAO.getSession(BaseHibernateDAO.java:13)
位于sor.hibernate.HitestTest.main(HitestTest.java:15)
原因:org.dom4j.DocumentException:http://www.jboss.org/dtd/hibernate/hibernate-mapping-4.0.dtd%20 嵌套异常:http://www.jboss.org/dtd/hibernate/hibernate-mapping-4.0.dtd%20
位于org.dom4j.io.SAXReader.read(SAXReader.java:484)
位于org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
... 还有13个
17-dic-2012 19.18.59 org.hibernate.cfg.Configuration
信息:HH000043:从资源配置:/hibernate.cfg.xml
17-dic-2012 19.18.59 org.hibernate.cfg.Configuration getConfigurationInputStream
信息:hh000040:配置资源:/hibernate.cfg.xml
17-dic-2012 19.18.59 org.hibernate.cfg.Configuration addResource
信息:hh000221:正在从资源读取映射:sor/hibernate/Hitest.hbm.xml
%%%%创建SessionFactory%%%时出错
org.hibernate.InvalidMappingException:无法读取XML
位于org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
位于org.hibernate.cfg.Configuration.add(Configuration.java:478)
位于org.hibernate.cfg.Configuration.add(Configuration.java:474)
在org.hibernate.cfg.Configuration.add上(Configuration.java:647)
位于org.hibernate.cfg.Configuration.addResource(Configuration.java:730)
位于org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2109)
位于org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2081)
位于org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2061)
位于org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2014)
位于org.hibernate.cfg.Configuration.configure(Configuration.java:1929)
位于org.hibernate.cfg.Configuration.configure(Configuration.java:1908)
位于sor.hibernate.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:71)
位于sor.hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:55)
在sor.hibernate.BaseHibernateDAO.getSession(BaseHibernateDAO.java:13)
位于sor.hibernate.HitestTest.main(HitestTest.java:15)
原因:org.dom4j.DocumentException:http://www.jboss.org/dtd/hibernate/hibernate-mapping-4.0.dtd%20 嵌套异常:http://www.jboss.org/dtd/hibernate/hibernate-mapping-4.0.dtd%20
位于org.dom4j.io.SAXReader.read(SAXReader.java:484)
位于org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
... 14多
线程“main”java.lang.NullPointerException中出现异常
位于sor.hibernate.HitestTest.main(HitestTest.java:15)
测试程序是

package sor.hibernate;


import java.util.Date;

import org.hibernate.Session;
import org.hibernate.Transaction;


public class HitestTest {

    public static void main(String[] args) {

        HitestDAO dao = new HitestDAO();
        Transaction tx = dao.getSession().beginTransaction();

        Hitest hitest[] = new Hitest[10];
        for (int i = 0; i < hitest.length; i++) {
            hitest[i]  = new Hitest();
            hitest[i].setGreeting("saluto numero " + i*23);
            hitest[i].setRef(i+10);
            hitest[i].setDate(new Date(System.currentTimeMillis()));
            dao.save(hitest[i]);
        }
        tx.commit();
        dao.getSession().close();
    }
}
包sor.hibernate;
导入java.util.Date;
导入org.hibernate.Session;
导入org.hibernate.Transaction;
公共类hitest{
公共静态void main(字符串[]args){
HitestDAO=新的HitestDAO();
事务tx=dao.getSession().beginTransaction();
Hitest Hitest[]=新的Hitest[10];
for(int i=0;i
并且hibernate.cfg.xml是

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    <session-factory>
        <property name="hbm2ddl.auto">update</property>
        <property name="dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <property name="connection.url">
            jdbc:mysql://localhost:3306/efeulib
        </property>
        <property name="connection.username">root</property>
        <property name="connection.password">qwerty</property>
        <property name="connection.driver_class">
            com.mysql.jdbc.Driver
        </property>
        <property name="myeclipse.connection.profile">
            mysqlJDriver
        </property>
        <mapping resource="sor/hibernate/Hitest.hbm.xml" />

    </session-factory>

</hibernate-configuration>

更新
org.hibernate.dialogue.mysqldialogue
jdbc:mysql://localhost:3306/efeulib
根
qwerty
com.mysql.jdbc.Driver
mysqlJDriver
而Hitest.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 package="sor.hibernate">
    <class name="sor.hibernate.Hitest" table="hitest" catalog="test">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <property name="greeting" type="java.lang.String">
            <column name="greeting" length="200" />
        </property>
        <property name="date" type="java.util.Date">
            <column name="date" length="10" />
        </property>
        <property name="ref" type="java.lang.Integer">
            <column name="ref" />
        </property>
    </class>
</hibernate-mapping>

<?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 package="sor.hibernate">
    <class name="sor.hibernate.Hitest" table="hitest" catalog="test">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="assigned" />
        </id>
        <property name="greeting" type="java.lang.String">
            <column name="greeting" length="200" />
        </property>
        <property name="date" type="java.util.Date">
            <column name="date" length="10" />
        </property>
        <property name="ref" type="java.lang.Integer">
            <column name="ref" />
        </property>
    </class>
</hibernate-mapping>
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd "
                                                       ^-- here
<property name="javax.persistence.validation.mode">none</property>
<?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="sor.hibernate.Hitest" table="hitest" catalog="test">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="increment" />
        </id>
        <property name="greeting" type="java.lang.String">
            <column name="greeting" length="200" />
        </property>
        <property name="date" type="java.util.Date">
            <column name="date" length="10" />
        </property>
        <property name="ref" type="java.lang.Integer">
            <column name="ref" />
        </property>
    </class>
</hibernate-mapping>