休眠4的功能性hibernate.cfg.xml [英] functional hibernate.cfg.xml for hibernate 4
问题描述
有人有休眠4的功能性cfg文件示例吗? 我可以在网上找到的所有参考文献均低于v4,并且无法正常工作.我尝试将文件内容粘贴到此处,但是此站点删除了hibernate-configuration标签.
does anybody have a functional cfg file example for hibernate 4 ? All the reference i can find online is for less than v4 and that doesn't work. i tried pasting the contents of my file here but this site removes the hibernate-configuration tag.
所以这就是结果:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/">
<hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration">
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">jdbc:mysql://localhost/foampile</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<!-- List of XML mapping files -->
<mapping resource="SiteRecord.hbm.xml"/>
</session-factory>
</hibernate-configuration>
一旦我更改为
<hibernate-configuration xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
我得到这个例外:
Caused by: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 63; Attribute "xmlns" must be declared for element type "hibernate-configuration".
已指定xmlns(xmlns ="http://www.hibernate.org/xsd/hibernate-configuration")
BUT xmlns IS specified (xmlns="http://www.hibernate.org/xsd/hibernate-configuration")
这是HIBERNATE 4.1中的一个错误???
IS THIS A BUG IN HIBERNATE 4.1 ???
推荐答案
我遇到了同样的问题,尽管文档和错误消息说了什么,但只要从hibernate配置中删除所有属性,我就能使它正常工作. :)因此,最后,我的DOCTYPE是这样的:
I had the same problem and I was able to get it to work by just removing all the attributes from hibernate-configuration, despite what the documentation and error messages say :) So in the end, I have this for my DOCTYPE:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
然后我就拥有:
<hibernate-configuration>
....
</hibernate-configuration>
这对我有用.
这篇关于休眠4的功能性hibernate.cfg.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!