Hibernate issue with using http://www.hibernate.org/dtd [duplicate]

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

This question already has an answer here:

I'm currently using http://hibernate.sourceforge.net as my namespace in my hibernate configuration files which gives me these warnings:

Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

So I tried switching hibernate.cfg.xml and all the other *.hbm.xml files to using http://www.hibernate.org/dtd. However then when I try to generate the code using hibernate tools in eclipse I get the following error message (code generation works fine with the other namespace):

org.hibernate.HibernateException: Could not parse configuration: C:\dev\workspace\DataLoad\hibernate.cfg.xml Could not parse configuration: C:\dev\workspace\DataLoad\hibernate.cfg.xml
org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org www.hibernate.org Nested exception: www.hibernate.org org.dom4j.DocumentException: www.hibernate.org Nested exception: www.hibernate.org www.hibernate.org Nested exception: www.hibernate.org

Here's my hibernate.cfg.xml:

             com.mysql.jdbc.Driver                      jdbc:mysql://localhost:3306/findata?tcpKeepAlive=true         rootxxxxxxxx2true             org.hibernate.dialect.MySQLDialect         thread             org.hibernate.cache.NoCacheProvider         

回答1:

We had also some problems parsing hibernate cfg files in last time. The root of the cause was that the hibernate site was unreachable. After some googling and debugging org.hibernate.util.DTDEntityResolver class, I realized that there is also another way, how to specify the DTD URL:

 

This means that hibernate will load the DTD from classpath - it is usually included in hibernate jar in org/hibernate directory.

However, we use hibernate 3.5.6 - I don't hnow if this approach still works in the newer version - give it a try. The benefit of this is that you are completely independent on internet connection, proxies and so on.



回答2:

Check this migration guide: https://community.jboss.org/wiki/HibernateCoreMigrationGuide36

You have to change the dtd url to http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!