第一次在eclipse上配置hibernate,问题百出啊,比如下面的org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml问题,知道是

hibernate.cfg.xml配置问题解决有问题,但不知道问题在哪,从Oracle的数据库的链接到po代码,各种找啊。

  1. log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
  2. log4j:WARN Please initialize the log4j system properly.
  3. org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
  4. at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1376)
  5. at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
  6. at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
  7. at test.Query.main(Query.java:15)
  8. Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
  9. at org.dom4j.io.SAXReader.read(SAXReader.java:484)
  10. at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1366)
  11. ... 3 more
  12. Exception in thread "main" java.lang.NullPointerException
  13. at test.Query.main(Query.java:20)

下面是Oracle的hibernate的数据库连接配置(/hibernate.cfg.xml):

  1. <hibernate-configuration>
  2. <session-factory>
  3. <property name="show_sql">true</property>
  4. <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
  5. <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  6. <property name="hibernate.connection.url">jdbc:oracle:thin:@Ip地址</property>
  7. <property name="hibernate.connection.username">用户名</property>
  8. <property name="hibernate.connection.password">密码</property>
  9. <mapping resource="com/po/Policy.hbm.xml"></mapping>
  10. </session-factory>
  11. </hibernate-configuration>

下面是po的配置(/po.hbm.xml):

  1. <hibernate-mapping package="com.po">
  2. <class name="Policy" table="T_policy_general">
  3. <id name="POLICY_ID" column="POLICY_ID">
  4. <generator class="assigned" />
  5. </id>
  6. <property name="PRODUCT_ID" column="PRODUCT_ID" />
  7. <property name="STATUS_ID" column="STATUS_ID" />
  8. <property name="POLICY_NO" column="POLICY_NO" />
  9. </class>
  10. </hibernate-mapping>

最后发现问题居然是xml文件头写的不对:

网上的错误写法:

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

正确写法:

  1.   /hibernate.cfg.xml
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

  /po.hbm.xml

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3. "-//Hibernate/hibernate-Mapping DTD 3.0//EN"
  4. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

最后成功查询到数据.

总结:不同xml的头是不一样的。

关于Could not parse configuration: /hibernate.cfg.xml的问题的更多相关文章

  1. org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml

    org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml at org.hibernate ...

  2. 解决离线Could not parse configuration:hibernate.cfg.xml错误

    离线使用hibernate tool 生成反向工程,在配置 配置文件完,生成配置文件后,会报出org.hibernate.HibernateException: Could not parse con ...

  3. Could not parse configuration: /hibernate.cfg.xml

    hibernate需要联网验证dtd,错误原因:未联网或网速不行

  4. org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xm

    org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xm 检查jar包是否正确以及配置的xm ...

  5. [原创]java WEB学习笔记77:Hibernate学习之路---Hibernate 版本 helloword 与 解析,.环境搭建,hibernate.cfg.xml文件及参数说明,持久化类,对象-关系映射文件.hbm.xml,Hibernate API (Configuration 类,SessionFactory 接口,Session 接口,Transaction(事务))

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  6. spring applicationContext.xml和hibernate.cfg.xml设置

    applicationContext.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans ...

  7. hibernate.cfg.xml常见配置

    转载自:http://blog.csdn.net/qiaqia609/article/details/9456489 <!--标准的XML文件的起始行,version='1.0'表明XML的版本 ...

  8. hibernate配置文件hibernate.cfg.xml和.hbm.xml的详细解释

    原文地址:http://blog.csdn.net/qiaqia609/article/details/9456489 hibernate.cfg.xml -标准的XML文件的起始行,version= ...

  9. hibernate配置文件hibernate.cfg.xml的详细解释

    <!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式-->                 <?x ...

随机推荐

  1. 做XH2.54杜邦线材料-导线

    好多市场上买的杜邦线质量一般,今天选了一种别的线 线色:红 黑   黄 绿 白 棕 蓝 线规:正标UL1007-24AWG 产品说明:          * UL1007电子连接线   * 线号:24 ...

  2. Spring Data JPA Tutorial Part Nine: Conclusions(未翻译)

    This is the ninth and the last part of my Spring Data JPA tutorial. Now it is time to take a look of ...

  3. Unity3D之游戏暂停制作方法记录

    在游戏开发中我们一般都需要涉及到一个功能:游戏暂停,但是这里指的暂停仅仅是核心模块的暂停,并不是整个游戏都暂停,比如一些UI和UI上的动画与特效是不能被暂停的,整个游戏都暂停了玩家该如何继续游戏呢. ...

  4. 关于TCP主动关闭连接中的wait_timeout

    首先我们先来回顾一下tcp关闭连接的过程: 假设A和B连接状态为EST,A需要主动关闭: A发送FIN给B,并将状态更改为FIN_WAIT1, B接收到FIN将状态更改为CLOSE_WAIT,并回复A ...

  5. C#文件后缀名详解

    C#文件后缀名详解 .sln:解决方案文件,为解决方案资源管理器提供显示管理文件的图形接口所需的信息. .csproj:项目文件,创建应用程序所需的引用.数据连接.文件夹和文件的信息. .aspx:W ...

  6. How to Be Good at Mathematics

    How to Be Good at Mathematics Community Q&A Sometimes, the hardest subject for some people is ma ...

  7. Eclipse10大快捷键组合

    一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升. Ctrl+Shift+C 快速单行注释 也适用于 ...

  8. 为什么监听不到开机广播action.BOOT_COMPLETED

    为什么监听不到开机广播action.BOOT_COMPLETED 1. 说明 Android手机开机后,会发送android.intent.action.BOOT_COMPLETED广播,监听这个广播 ...

  9. mac上java开发环境

    刚刚入手 macbook 还是 按照window 的方式,下载java,安装,配置环境变量,下载maven安装配置 等等....非常繁琐.. but 在mac上不用这么复杂...利用 brew 命令去 ...

  10. C++ 预编译头文件

    1.解决什么问题? C++ 编译器是单独,分别编译的,每个cpp文件,进行预编译(也就是对#include,define 等进行文本替换),生成编译单元.编译单元是一个自包含文件,C++编译器对编译单 ...