3

我目前在我的休眠配置文件中使用http://hibernate.sourceforge.net作为我的命名空间,这给了我这些警告:

已识别过时的休眠命名空间 http://hibernate.sourceforge.net/。请改用命名空间 http://www.hibernate.org/dtd/。请参考 Hibernate 3.6 迁移指南!

因此,我尝试将 hibernate.cfg.xml 和所有其他 *.hbm.xml 文件切换为使用http://www.hibernate.org/dtd。但是,当我尝试在 eclipse 中使用休眠工具生成代码时,我收到以下错误消息(代码生成与其他命名空间一起工作):

org.hibernate.HibernateException:无法解析配置:C:\dev\workspace\DataLoad\hibernate.cfg.xml 无法解析配置:C:\dev\workspace\DataLoad\hibernate.cfg.xml
org.dom4j.DocumentException: www.hibernate.org 嵌套异常:www.hibernate.org www.hibernate.org 嵌套异常:www.hibernate.org org.dom4j.DocumentException:www.hibernate.org 嵌套异常:www.hibernate.org www.hibernate.org嵌套异常:www.hibernate.org

这是我的 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">

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">
            com.mysql.jdbc.Driver
        </property>
        <property name="connection.url">
            jdbc:mysql://localhost:3306/findata?tcpKeepAlive=true
        </property>
        <property name="connection.username">root</property>
        <property name="connection.password">xxxxxxxx</property>

        <property name="connection.pool_size">2</property>
        <property name="show_sql">true</property>
        <property name="dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">
            org.hibernate.cache.NoCacheProvider
        </property>

        <mapping resource="conf/Alert.hbm.xml" />
        <mapping resource="conf/Entity.hbm.xml" />
        <mapping resource="conf/FactData.hbm.xml" />
        <mapping resource="conf/TimeEvent.hbm.xml" />
        <mapping resource="conf/User.hbm.xml" />
        <mapping resource="conf/AlertTarget.hbm.xml" />
        <mapping resource="conf/LogAlert.hbm.xml" />
        <mapping resource="conf/RepeatType.hbm.xml" />
        <mapping resource="conf/Schedule.hbm.xml" />
        <mapping resource="conf/Task.hbm.xml" />
        <mapping resource="conf/JobQueue.hbm.xml" />
        <mapping resource="conf/LogTask.hbm.xml" />
        <mapping resource="conf/Exclude.hbm.xml" />
        <mapping resource="conf/LogNotification.hbm.xml" />
        <mapping resource="conf/Job.hbm.xml" />
        <mapping resource="conf/Metric.hbm.xml" />
        <mapping resource="conf/EntityGroup.hbm.xml" />
        <mapping resource="conf/ExtractSingle.hbm.xml" />
    </session-factory>
</hibernate-configuration>
4

2 回答 2

9

上次我们在解析休眠 cfg 文件时也遇到了一些问题。根本原因是休眠站点无法访问。经过一番谷歌搜索和调试 org.hibernate.util.DTDEntityResolver 类后,我意识到还有另一种方法,如何指定 DTD URL:

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

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

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

于 2012-07-10T09:28:15.057 回答
2

检查此迁移指南:https ://community.jboss.org/wiki/HibernateCoreMigrationGuide36

您必须将 dtd 网址更改为http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd

于 2014-02-10T22:31:49.520 回答