当前位置: 首页 > 面试题库 >

使用http://www.hibernate.org/dtd的休眠问题

单耘豪
2023-03-14
问题内容

我目前在hibernate配置文件中将http://hibernate.sourceforge.net用作我的命名空间,这给了我以下警告:

公认的过时的hibernate名称空间
http://hibernate.sourceforge.net/。请改用名称空间
http://www.hibernate.org/dtd/。请参阅《
Hibernate 3.6迁移指南》!

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

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>

问题答案:

我们在上次解析hibernatecfg文件时也遇到了一些问题。原因的根源是hibernate站点无法访问。在对org.hibernate.util.DTDEntityResolver类进行了一些搜索和调试之后,我意识到还有另一种方法,如何指定DTD
URL:

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

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

但是,我们使用的是hibernate3.5.6-我不知道这种方法在新版本中是否仍然有效-试试看。这样做的好处是您完全独立于Internet连接,代理等。



 类似资料:
  • 我想用XML配置文件与Hibernate一起工作。 这hibernate.cfg.xml文件: 当我运行我的应用程序我得到的错误: 组织。xml。萨克斯。SAXException:无效的系统标识符:http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd在太阳下。util。xml。PlatformXmlPropertiesProvid

  • 问题内容: 我有一个Spring和Hibernate3在生产中运行良好的应用程序。以下是Spring的applicationContext.xml中会话工厂的配置 生产正常。 现在,对于另一个项目,我们正在迁移到Hibernate4。我们使用org.springframework.orm.hibernate4。*包中的Hibernate 4的SessionFactory,TransacionMan

  • 问题内容: 我正在寻找展示如何将MongoDB与Hibernate集成的资源(最好是在Spring内),以便我可以在RDBMS和NoSql替代品之间进行切换:有人有这样做的经验吗? 问题答案: 您不能轻易做到这一点。Hibernate的重点是将Java对象映射到关系数据库。尽管Hibernate提取了许多细节,但您仍然需要了解关系数据库如何与诸如外键和主键之类的东西一起工作,以及运行查询对性能的影

  • 问题内容: 我已经使用Seam 2.2.1和MySQL编写了一个正在运行的应用程序。我现在尝试将应用程序连接到 Informix, 并且当我从 hibernate ()执行查询时,出现以下异常: org.hibernate.exception.genericjdbcexception无法执行查询 当我执行查询时,执行成功。 生成的sql是 选择前2个user0_.USER_ID作为USER1_12

  • 问题内容: 我正在使用hibernate状态向下转换query.uniqueResult()来处理问题。我有2类:-UserBean-UserLogin 在第一个中,我具有所有表字段以及所有处理数据的方法的映射。相反,第二个仅代表将存储在用户会话中的一些用户数据。 在登录方法的特定点,我执行查询并得到1行(我已经检查了查询是否确实返回了一些结果)。关键是我无法从Object类型(即query.un

  • 问题内容: 下面的函数是我在Web应用程序中具有的按钮的actionListener,我正在从数据库中的表中删除旧选择的行,并将新行插入数据库中。 我一直在例外:会话关闭!有人可以解释一下如何在hibernate状态下关闭会话(自动吗?)以及如何使用它们。 这是该异常的详细堆栈跟踪: 谢谢, 问题答案: 在Hibernate会话显然配置为基于请求的情况下,您在会话范围内的受管Bean中使用了延迟获