关于Could not parse configuration: /hibernate.cfg.xml的问题
第一次在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的问题的更多相关文章
- org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml at org.hibernate ...
- 解决离线Could not parse configuration:hibernate.cfg.xml错误
离线使用hibernate tool 生成反向工程,在配置 配置文件完,生成配置文件后,会报出org.hibernate.HibernateException: Could not parse con ...
- Could not parse configuration: /hibernate.cfg.xml
hibernate需要联网验证dtd,错误原因:未联网或网速不行
- org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xm
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xm 检查jar包是否正确以及配置的xm ...
- [原创]java WEB学习笔记77:Hibernate学习之路---Hibernate 版本 helloword 与 解析,.环境搭建,hibernate.cfg.xml文件及参数说明,持久化类,对象-关系映射文件.hbm.xml,Hibernate API (Configuration 类,SessionFactory 接口,Session 接口,Transaction(事务))
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- spring applicationContext.xml和hibernate.cfg.xml设置
applicationContext.xml配置 <?xml version="1.0" encoding="UTF-8"?> <beans ...
- hibernate.cfg.xml常见配置
转载自:http://blog.csdn.net/qiaqia609/article/details/9456489 <!--标准的XML文件的起始行,version='1.0'表明XML的版本 ...
- hibernate配置文件hibernate.cfg.xml和.hbm.xml的详细解释
原文地址:http://blog.csdn.net/qiaqia609/article/details/9456489 hibernate.cfg.xml -标准的XML文件的起始行,version= ...
- hibernate配置文件hibernate.cfg.xml的详细解释
<!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> <?x ...
随机推荐
- jQuery基础学习3——jQuery库冲突
默认情况下,jQuery用$作为自身的快捷方式. jQuery库在其他库之后导入 在其他库和jQuery库都被加载完毕后,可以在任何时候调用jQuery.noConflict()函数来将变量$的控制权 ...
- [置顶] 新修改ADB,支持Android 4.2 系统 ,全部中文命令,手机屏幕截图等等
发过好几个ADB的工具,有很多朋友用了之后给我反馈了不少的意见和bug,这里非常感谢他们,所以今天花了一天的时间重新整理了一下ADB,并且修改了这些BUG.也有朋友建议我给一个修改列表,今天发这个帖子 ...
- 用BenchmarkDotNet给C#程序做性能测试
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:用BenchmarkDotNet给C#程序做性能测试.
- 《JavaScript高级程序设计》 读书笔记(三)
操作符 递增和递减操作符 var num1 = 2; var num2 = 20; var num3 = --num1 + num2; // 等于 21 var num4 = num1 + num2; ...
- 解决Linux下sqlplus中文乱码问题
错误现象:在windows下用其他工具访问oracle,确认中文正常显示.在Linux下使用sqlplus查询数据表中文内容出现乱码. 分析及解决:因为windows下正常,所以问题应出现在Linux ...
- Oracle RMAN 清除归档日志
在开发环境及UAT环境经常碰到需要清除归档日志的情形,对于这个问题方法有很多.可以直接使用rm方式清除归档日志,也可以使用find命令来查找符合条件的记录来清除归档日志,或者直接写个shell脚本来搞 ...
- PostgreSQL的 initdb 源代码分析之二十一
继续分析: setup_schema(); 展开: 实质就是创建info_schema. cmd 是: "/home/pgsql/project/bin/postgres" --s ...
- 错误号码2003 Can't connect to MySQL server 'localhost' (0)
错误描写叙述 错误原因 近期,我一直都能够用SQLyog连接本地数据库,可是近几天却无法连接:而且一直都报上述错误,我查阅了非常多资料,发现有非常多中说法 总结一下 第一,MySQL中的my.ini出 ...
- python的一些总结3
好吧 刚刚的2篇文章都很水.. 这篇 也是继续水 在 templates 右键新建 html 文件:如 index.html (输入以下代码) <!DOCTYPE html> <ht ...
- Codeforces Beta Round #51 B. Smallest number dfs
B. Smallest number Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/pro ...