解析配置/ hibernate.cfg.xml时出错?

时间:2014-07-10 19:24:55

标签: java hibernate java-ee

我的XML文件

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "http://www.hibernate.sourceforge.net/dtd/hibernate-configuration-3.0.dtd">


<hibernate-configuration>
   <session-factory>
       <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

       <property name="connection.url">jdbc:oracle:thin:@192.168.252.128:1521:orcl</property>

       <property name="connection.username">system</property>

       <property name="connection.passowrd">manager</property>

       <property name="dialect">org.hibernate.dialect.OracleDialect</property>

       <property name="show_sql">true</property>

       <property name="hbm2ddl.auto">update</property>

       <mapping class="com.nttdata.domain.Employee"/>

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

执行后的控制台::

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: problem parsing configuration/hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1222)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)
    at com.nttdata.util.HibernateUtil.getSessionFactory(HibernateUtil.java:11)
    at com.nttdata.dao.EmployeeDao.saveEmployee(EmployeeDao.java:13)
    at com.nttdata.client.Driver.main(Driver.java:10)
Caused by: org.dom4j.DocumentException: www.hibernate.sourceforge.net Nested exception: www.hibernate.sourceforge.net
    at org.dom4j.io.SAXReader.read(SAXReader.java:484)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
    ... 5 more

任何帮助都有什么错误?

2 个答案:

答案 0 :(得分:0)

尝试将DOCTYPE更改为:

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

答案 1 :(得分:0)

<!DOCTYPE hibernate-configuration SYSTEM
    "classpath://org/hibernate/hibernate-configuration-3.0.dtd">

这意味着hibernate将从类路径加载DTD - 它通常包含在org / hibernate目录的hibernate jar中。

但是,我们使用hibernate 3.5.6 - 我不知道如果这种方法在新版本中仍然有效 - 请试一试。这样做的好处是您完全独立于互联网连接,代理等。

休眠配置文件位置

第一个解决方案是使用classpath在系统中提供DTD文件位置。因此离线工作的DocType将是;

<!DOCTYPE hibernate-configuration SYSTEM 
    "classpath://org/hibernate/hibernate-configuration-3.0.dtd">

将SourceForge DTD URL与SYSTEM

一起使用

我发现的另一个解决方案是将DTD URL更改为SourceForge并将声明从PUBLIC更改为SYSTEM。

如果您的系统处于离线状态,那么下面也会有效。

<!DOCTYPE hibernate-configuration SYSTEM 
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
相关问题