2012-10-29 48 views
3

我想部署一個簡單的EJB項目到Jboss 7.1.1上。我有一個H2數據庫的單獨安裝。persistence.xml中的錯誤

所以我改變了standalone.xml如下:

 <subsystem xmlns="urn:jboss:domain:datasources:1.0"> 
      <datasources> 
       <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"> 
        <connection-url>jdbc:h2:tcp://localhost/~/test</connection-url> 
        <driver>h2</driver> 
        <security> 
         <user-name>sa</user-name> 
         <password>sa</password> 
        </security> 
       </datasource> 
       <drivers> 
        <driver name="h2" module="com.h2database.h2"> 
         <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> 
        </driver> 
       </drivers> 
      </datasources> 
     </subsystem> 

現在我還編輯persistence.xml中在standalone.xml

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
    <persistence-unit name="scube" transaction-type="JTA"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <class>com.sample.model.Property</class> 

     <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> 

     <properties> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" /> 
      <property name="hibernate.max_fetch_depth" value="3" /> 
      <property name="hibernate.hbm2ddl.auto" value="update" /> 
      <property name="hibernate.show_sql" value="true" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

Eclipse中的名稱一致,指向一個誤差在線路:JAVA:JBoss的/數據源/ ExampleDS
錯誤如下:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'jta-data-source'. One of '{"http://java.sun.com/xml/ns/persistence":class, "http://java.sun.com/ 
xml/ns/persistence":exclude-unlisted-classes, "http://java.sun.com/xml/ns/persistence":shared-cache-mode, "http://java.sun.com/xml/ns/persistence":validation-mode, 
"http://java.sun.com/xml/ns/persistence":properties}' is expected. 

我搜索了類似的錯誤,所有的解決方案都說xml元素的順序很重要,我檢查過的或者jndi的名字應該和standalone.xml匹配,後者確實匹配。

有人可以幫助我?

回答

8

XML元素(根據模式文檔)的正確順序是:

<provider>org.hibernate.ejb.HibernatePersistence</provider> 
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> 
<class>com.sample.model.Property</class> 
+0

哦,我怎麼會錯過。謝謝@Piotr –