用于hibernate 4的函数hibernate.cfg.xml

时间:2012-08-30 22:51:59

标签: hibernate

有没有人有hibernate 4的功能cfg文件示例? 我在网上找到的所有参考文献都是低于v4,但是不起作用。我尝试粘贴我的文件的内容,但这个网站删除了hibernate配置标记。

所以出现的是:

<?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”)

这是HIBERNATE 4.1中的一个BU ???

2 个答案:

答案 0 :(得分:2)

我有同样的问题,我能够通过删除hibernate-configuration中的所有属性来实现它,尽管文档和错误消息说的是:)所以最后,我有这个用于我的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>

这对我有用。

答案 1 :(得分:1)

...为了它的价值,我最终让IntelliJ创建了存根文件,只是为了开始它(对于hibernate 4.1):

<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">