2012-08-30 61 views
6

有没有人有一个功能性的cfg文件示例hibernate 4? 我可以在网上找到的所有参考文献的版本少于v4版,并且不起作用。我尝试粘贴我的文件的内容,但是这个网站删除了hibernate-configuration标签。休眠功能hibernate.cfg.xml 4

所以这里是什么出来:

<?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". 

BUT的xmlns指定(的xmlns =“HTTP ://www.hibernate.org/xsd/hibernate-configuration“)

这是一个在汉堡4.1的错误?

+0

看起来像问题是!DOCTYPE,但我不知道要设置它。如果我将它设置为引用v3 DTD的引用,那么它将无法再次解析,如果我不包含doctype,它会抱怨hibernate-configuration缺少xmlns属性......我极其沮丧地最后2 HRS – amphibient

+0

Hibernate 4在线文档显示没有任何DOCTYPE的示例。 – amphibient

+0

http://docs.jboss.org/hibernate/orm/4.1/devguide/en-US/html/ch01.html#d5e83 – amphibient

回答

1

...对于它的价值,我最后不得不创建的IntelliJ存根文件,只是为了得到它开始(对Hibernate 4.1):

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

我有同样的问题,我是能够得到它,尽管什么文件和错误消息到底:)所以说,仅仅取消所有从休眠配置的属性,工作,我为我的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> 

这对我很有用。