hibernate在不联网时不能解析配置文件解决方案
来源:互联网 发布:mysql having 用法 编辑:程序博客网 时间:2024/06/06 11:29
在做项目时通常用hibernate框架来进行数据库的一些操作,但是有时候网络条件差或者不联网的情况下,在对数据库进行增删改查操作时,总是会报下面的异常:
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xmlat org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)at org.wjp.hibernate.ExportDB.main(ExportDB.java:8)Caused by: org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.orgat org.dom4j.io.SAXReader.read(SAXReader.java:484)at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)... 3 more
之前在做时没在意这些,后来通过查了一些资料,才知道了问题出现的原因所在。
我们可以看一下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"
而一般的xx.hbm.xml文件的开始部分代码如下:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
原因就出现在dtd文件那里,因为hibernate的两个配置文件分别都会默认去上面两个加粗的网站去找,所以当使用hibernate进行数据库操作时,如果你的
网络环境不好或者没联网,此时配置文件无法访问指定的dtd验证文件,所以才会出现xml无法解析的异常。
所以解决该问题的方法就是:在需要使用hibernate的项目里,通常在该项目中建立一个文件夹,里面用来存放用于验证hibernate.cfg.xml的dtd文件和验证xx.hbm.xml的dtd文件,例如如下代码,我在我的项目下建立了一个dtd文件夹,里面放了hibernate-configuration-3.0.dtd文件和hibernate-mapping-3.0.dtd文件:
xx.hbm.xml代码:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "dtd/hibernate-mapping-3.0.dtd">hibernate.cfg.xml代码:<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "dtd/hibernate-configuration-3.0.dtd">
这时无论在联网或者非联网环境下使用hibernate时,其都会去你指定的路径去找对应的dtd,而不会去hibernate的官网去找对应的dtd,这样就不好再出现上面的xml无法解析的异常了。
0 0
- hibernate在不联网时不能解析配置文件解决方案
- hibernate在不联网时不能解析配置文件解决方案
- hibernate在不联网时不能解析配置文件解决方案
- [Java] Hibernate在不联网时不能解析配置文件解决方案
- hibernate在不联网时不能解析配置文件解决方案
- hibernate在不联网时不能解析配置文件解决方案
- 为什么hibernate在不联网的时候解析不了配置文件?(hibernate.cfg.xml)
- struts2的配置文件在不联网没有提示的解决办法
- Hibernate断网后不能解析cfg配置文件,连接失败的问题
- Hibernate配置文件加密解决方案
- Hibernate 未联网情况下不能根据dtd解析hbm.xml
- Hibernate配置文件解析
- hibernate配置文件详细解析
- Hibernate 配置文件解析
- 【SSH】Hibernate:配置文件解析
- hibernate 配置文件详细解析
- Hibernate 配置文件解析
- 安卓模拟器不能联网的解决方案
- iOS --- 如何暂停和继续CALayer上的动画
- Real-Time Rendering-第一章 Introduction
- 第二周《C语言及程序设计》实践项目32 循环思想启蒙:输出小星星
- 线程安全随机队列
- 安装eclipse的JRebel6.4.3的插件
- hibernate在不联网时不能解析配置文件解决方案
- leetcode318:Maximum Product of Word Lengths(medium)
- iOS --- 一张图看懂转场动画
- 对象的序列化和反序列化---使用Serializable接口
- scala进阶14-自身类型self type
- 蚁群算法
- log4j.properties配置详解
- resolve in ui-router
- HDU 1052 Tian Ji -- The Horse Racing