2011-12-20 72 views
5

在Hibernate 4中我發現(新的)我可能使用XSD模式而不是DTD。Hibernate 4中新的XSD模式

<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping"     
    xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping hibernate-mapping-4.0.xsd" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

但架構位置無效,在初始化期間我有錯誤。

有沒有人知道Hibernate 4中的XSD有什麼問題?

+0

如果需要,以下是Hibernate配置文件的XML Schema Definition文件的工作位置(現在):** http://hibernate.org/xsd/hibernate-configuration/hibernate-configuration-4.0 .xsd **您可以在'xsi:schemaLocation'屬性中使用它。以下頁面提供了可用於Hibernate的XSD文件的鏈接(目前只有_one_ XSD):http://hibernate.org/xsd/hibernate-configuration/。 – informatik01 2016-11-13 21:27:12

回答

2

模式位置只是地點的標識符,而且這個地方可以綁定到任何地方:互聯網,本地驅動器。特別是這個模式(連同hibernate-configuration-4.0.xsd)被放置在包org.hibernate中的hibernate-core jar中。由於schemaLocation和實際位置通常是相同的,因此IDE會嘗試從它指向的位置獲取它,但這不是我們的情況。 您可以將IDE配置爲在此jar中查找此架構,以便您可以使用自動完成。如果我們正在討論IntelliJ,那麼請轉到設置並配置您的Schema和DTD以包含所需的模式。

+0

謝謝,但目前有很多觸發xsd模式使用的問題。 Hibernate Dev Team將在下一個主要版本5.0.0中修復其中的一部分,因此現在遷移到這個xsd是不可行的。 – smg 2013-01-22 21:43:11

6
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping" 
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping classpath://org/hibernate/hibernate-mapping-4.0.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" package="acme.foo.bar"/> 

試試這個,它應該更好。

+0

這對任何人都適用嗎?我試過了,它不起作用... – 2014-12-19 14:54:58

+0

只需在IntelliJ://org/hibernate/hibernate-mapping-4.0.xsd – zhy2002 2015-10-26 06:19:55