Hibernate配置文件解析异常

时间:2014-02-26 05:14:02

标签: hibernate

在运行程序期间我收到的错误消息

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
    at SimpleTest.main(SimpleTest.java:11)
Caused by: org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
    ... 3 more

配置文件是我使用的 数据库连接设置是正确的我确定..

 <?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">

              <hibernate-configuration>

              <session-factory>

                 <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password"></property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">true</property>
                  <property name="current_session_context_class">thread</property>


                  <!-- _________ Defining the Mapping Files ___________ -->

                  <mapping resource="Lecturer.hbm.xml" />

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

与hibernate.cfg.xml连接的主类就像这样

public class SimpleTest {

                public static void main(String[] args) {
                    System.out.println("innnnnnnnnn");
                    SessionFactory sessionFactory = new
                       Configuration().configure().buildSessionFactory();
                    Session session = sessionFactory.getCurrentSession();
                    Transaction tx = session.beginTransaction();

                    Lecturer lecturer1 = new Lecturer();
                    lecturer1.setFirstName("Fatma");
                    lecturer1.setLastName("Meawad");

                    session.save(lecturer1);
                    tx.commit();

                }
              }

table and every think will be created

请告诉我错误的地方

1 个答案:

答案 0 :(得分:0)

在SimpleTest类中尝试这个,

Session session = sessionFactory.openSession();
相关问题