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

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

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

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

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

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

 <hibernate-mapping package="com.po">
     <class name="Policy" table="T_policy_general">
         <id name="POLICY_ID" column="POLICY_ID">
             <generator class="assigned" />
         </id>
         <property name="PRODUCT_ID" column="PRODUCT_ID" />
         <property name="STATUS_ID" column="STATUS_ID" />
         <property name="POLICY_NO" column="POLICY_NO" />
     </class>
 </hibernate-mapping>  

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

网上的错误写法:

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

正确写法:

  /hibernate.cfg.xml
 <?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">

  /po.hbm.xml

 <?xml version='1.0' encoding='UTF-8'?>
 <!DOCTYPE hibernate-mapping PUBLIC
           "-//Hibernate/hibernate-Mapping DTD 3.0//EN"
           "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. Light oj 1236 - Pairs Forming LCM (约数的状压思想)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1236 题意很好懂,就是让你求lcm(i , j)的i与j的对数. 可以先预处理1e7以 ...

  2. Mysqlbinlog使用

    Mysqlbinlog使用   1.binlog日志打开方法 在my.cnf这个文件中加一行(Windows为my.ini).#vi /etc/my.cnf[mysqld]log-bin=mysqlb ...

  3. 最小较小codeforces 2B The least round way

    查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记载吧! 求从左上角到右下角所经过的数字之积末端所含0最小的个数 终究的积可以当作A*2^x*5^y, ...

  4. 定义member【C++】cstddef中4个定义

    最近研究定义member,稍微总结一下,以后继续补充: size_t size_t corresponds to the integral data type returned by the lang ...

  5. [原创,分享]DbHelper 续

    一直在想怎么样才能让dbHelper更简单,更灵活,更僵化.终于我发布了第一个开源版本的dbhelper.此helper将使用System.Data.DbHelper作为命名空间.采用内部驱动与内容S ...

  6. Ruby on Rails Tutorial 第四章 Rails背后的Ruby 之 其他数据类型(二)

    1.方法 定义如下所示: def string_message(str='') if str.empty? "It's an empty string!" else "T ...

  7. SQL SERVER 中identity用法

    在数据库中, 常用的一个流水编号通常会使用 identity 栏位来进行设置, 这种编号的好处是一定不会重覆, 而且一定是唯一的, 这对table中的唯一值特性很重要, 通常用来做客户编号, 订单编号 ...

  8. __asm__ __volatile__("": : :"memory");

    参考:http://stackoverflow.com/questions/14950614/working-of-asm-volatile-memory asmvolatile("&quo ...

  9. UITableView优化技巧

    UITableView的简单认识 UITableView最核心的思想就是UITableViewCell的重用机制.简单的理解就是:UITableView只会创建一屏幕(或一屏幕多一点)的UITable ...

  10. 2012第二届GIS制图大赛——公开课技术问题&答疑(珍贵资源哦!)(http://blog.csdn.net/arcgis_all/article/details/8216984)

    本次制图大赛培训的公开课结束后,我们把所有技术问题收集并进行统一解答,现将这些资料在博文中分享. 由于这些问题涉及了制图技术中较多普遍性的内容,因此是非常珍贵的资源,希望能对大家有帮助. ——符号及符 ...