关于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 ...
随机推荐
- 做XH2.54杜邦线材料-导线
好多市场上买的杜邦线质量一般,今天选了一种别的线 线色:红 黑 黄 绿 白 棕 蓝 线规:正标UL1007-24AWG 产品说明: * UL1007电子连接线 * 线号:24 ...
- 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 ...
- Unity3D之游戏暂停制作方法记录
在游戏开发中我们一般都需要涉及到一个功能:游戏暂停,但是这里指的暂停仅仅是核心模块的暂停,并不是整个游戏都暂停,比如一些UI和UI上的动画与特效是不能被暂停的,整个游戏都暂停了玩家该如何继续游戏呢. ...
- 关于TCP主动关闭连接中的wait_timeout
首先我们先来回顾一下tcp关闭连接的过程: 假设A和B连接状态为EST,A需要主动关闭: A发送FIN给B,并将状态更改为FIN_WAIT1, B接收到FIN将状态更改为CLOSE_WAIT,并回复A ...
- C#文件后缀名详解
C#文件后缀名详解 .sln:解决方案文件,为解决方案资源管理器提供显示管理文件的图形接口所需的信息. .csproj:项目文件,创建应用程序所需的引用.数据连接.文件夹和文件的信息. .aspx:W ...
- How to Be Good at Mathematics
How to Be Good at Mathematics Community Q&A Sometimes, the hardest subject for some people is ma ...
- Eclipse10大快捷键组合
一个Eclipse骨灰级开发者总结了他认为最有用但又不太为人所知的快捷键组合.通过这些组合可以更加容易的浏览源代码,使得整体的开发效率和质量得到提升. Ctrl+Shift+C 快速单行注释 也适用于 ...
- 为什么监听不到开机广播action.BOOT_COMPLETED
为什么监听不到开机广播action.BOOT_COMPLETED 1. 说明 Android手机开机后,会发送android.intent.action.BOOT_COMPLETED广播,监听这个广播 ...
- mac上java开发环境
刚刚入手 macbook 还是 按照window 的方式,下载java,安装,配置环境变量,下载maven安装配置 等等....非常繁琐.. but 在mac上不用这么复杂...利用 brew 命令去 ...
- C++ 预编译头文件
1.解决什么问题? C++ 编译器是单独,分别编译的,每个cpp文件,进行预编译(也就是对#include,define 等进行文本替换),生成编译单元.编译单元是一个自包含文件,C++编译器对编译单 ...