Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error in persistence.xml

I am trying to deploy a simple EJB project onto Jboss 7.1.1. I have a separate installation of H2 database.

So I changed the standalone.xml as follows:

        <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>

Now I have also edited the persistence.xml to match the names in the 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, points an error at line: java:jboss/datasources/ExampleDS
Error is as follows:

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.

I searched for similar errors and all the resolutions said that either the order of xml elements were important, which I checked or the jndi name should match with standalone.xml, which does match.

Can someone help me with this?

like image 956
Sara.0 Avatar asked Jan 16 '23 04:01

Sara.0


1 Answers

The right order of XML elements (according to schema document) is:

<provider>org.hibernate.ejb.HibernatePersistence</provider> 
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> 
<class>com.sample.model.Property</class>
like image 143
Piotr Kochański Avatar answered Feb 18 '23 17:02

Piotr Kochański