问题描述
我目前在我的hibernate配置文件中使用作为我的命名空间它给了我这些警告:
lockquote
识别过时的hibernate命名空间
。改为使用命名空间
。请参阅Hibernate 3.6
迁移指南!
所以我尝试了切换hibernate.cfg.xml和所有其他* .hbm .xml文件转换为使用。然而,当我尝试在eclipse中使用hibernate工具生成代码时,我得到以下错误消息(代码生成可以与其他命名空间一起工作):
这是我的hibernate.cfg.xml:
<?xml version ='1.0'encoding ='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://www.hibernate.org/dtd/hibernate-configuration -3.0.dtd>
< hibernate-configuration>
< session-factory>
< property name =connection.driver_class>
com.mysql.jdbc.Driver
< / property>
< property name =connection.url>
jdbc:mysql:// localhost:3306 / findata?tcpKeepAlive = true
< / property>
< property name =connection.username> root< / property>
< property name =connection.password> xxxxxxxx< / property>
< property name =connection.pool_size> 2< / property>
< property name =show_sql> true< / property>
< property name =dialect>
org.hibernate.dialect.MySQLDialect
< / property>
< property name =current_session_context_class>线程< / property>
< property name =cache.provider_class>
org.hibernate.cache.NoCacheProvider
< / property>
< mapping resource =conf / Alert.hbm.xml/>
< mapping resource =conf / Entity.hbm.xml/>
< mapping resource =conf / FactData.hbm.xml/>
< mapping resource =conf / TimeEvent.hbm.xml/>
< mapping resource =conf / User.hbm.xml/>
< mapping resource =conf / AlertTarget.hbm.xml/>
< mapping resource =conf / LogAlert.hbm.xml/>
< mapping resource =conf / RepeatType.hbm.xml/>
< mapping resource =conf / Schedule.hbm.xml/>
< mapping resource =conf / Task.hbm.xml/>
< mapping resource =conf / JobQueue.hbm.xml/>
< mapping resource =conf / LogTask.hbm.xml/>
< mapping resource =conf / Exclude.hbm.xml/>
< mapping resource =conf / LogNotification.hbm.xml/>
< mapping resource =conf / Job.hbm.xml/>
< mapping resource =conf / Metric.hbm.xml/>
< mapping resource =conf / EntityGroup.hbm.xml/>
< mapping resource =conf / ExtractSingle.hbm.xml/>
< / session-factory>
< / hibernate-configuration>
我们在上次解析hibernate cfg文件时也遇到一些问题时间。原因的根源在于休眠站点无法访问。经过一些搜索和调试org.hibernate.util.DTDEntityResolver类后,我意识到还有另外一种方式,如何指定DTD URL:
<!DOCTYPE hibernate-configuration SYSTEM
classpath://org/hibernate/hibernate-configuration-3.0.dtd>
这意味着hibernate会从classpath加载DTD - 它通常包含在org / hibernate目录。
然而,我们使用hibernate 3.5.6 - 如果这种方法仍然适用于新版本,我不会知道 - 试试看吧。这样做的好处是,你完全独立于互联网连接,代理等等。
I'm currently using http://hibernate.sourceforge.net as my namespace in my hibernate configuration files which gives me these warnings:
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):
Here's my hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/findata?tcpKeepAlive=true
</property>
<property name="connection.username">root</property>
<property name="connection.password">xxxxxxxx</property>
<property name="connection.pool_size">2</property>
<property name="show_sql">true</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<mapping resource="conf/Alert.hbm.xml" />
<mapping resource="conf/Entity.hbm.xml" />
<mapping resource="conf/FactData.hbm.xml" />
<mapping resource="conf/TimeEvent.hbm.xml" />
<mapping resource="conf/User.hbm.xml" />
<mapping resource="conf/AlertTarget.hbm.xml" />
<mapping resource="conf/LogAlert.hbm.xml" />
<mapping resource="conf/RepeatType.hbm.xml" />
<mapping resource="conf/Schedule.hbm.xml" />
<mapping resource="conf/Task.hbm.xml" />
<mapping resource="conf/JobQueue.hbm.xml" />
<mapping resource="conf/LogTask.hbm.xml" />
<mapping resource="conf/Exclude.hbm.xml" />
<mapping resource="conf/LogNotification.hbm.xml" />
<mapping resource="conf/Job.hbm.xml" />
<mapping resource="conf/Metric.hbm.xml" />
<mapping resource="conf/EntityGroup.hbm.xml" />
<mapping resource="conf/ExtractSingle.hbm.xml" />
</session-factory>
</hibernate-configuration>
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:
<!DOCTYPE hibernate-configuration SYSTEM
"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
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.
这篇关于Hibernate问题与使用http://www.hibernate.org/dtd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!