![](/img/trans.png)
[英]Session Factory could not be created.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
[英]HibernateException “Could not parse configuration: hibernate.cfg.xml” error while running a simple Hibernate Application
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at com.javatpoint.mypackage.StoreData.main(StoreData.java:13)
Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
... 2 more
為什么會發生此HibernateException?
這很可能是由於所使用的Hibernate jar中不存在的hibernate.cfg.xml
頂部引用了DTD引起的。
假設您沒有使用Hibernate 2.0版,請檢查hibernate.cfg.xml中是否位於頂部:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
並且如果您使用XML hbm文件進行實體映射,那么在這些XML文件中,您最需要注意的是:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.