4

I have the following persistence

There is a code snippet:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="ProcedimientosAlmacenados">
    <jta-data-source>java:/jdbc/DesaAppDS</jta-data-source>
    <properties> 
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
        <property name="hibernate.hbm2ddl.auto" value="validate" />
        <property name="hibernate.ejb.entitymanager_factory_name" value="ProcedimientosAlmacenados" />
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
        <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="openjpa.TransactionMode" value="managed" />
        <property name="openjpa.ConnectionFactoryMode" value="managed" />
        <property name="openjpa.jdbc.DBDictionary" value="db2" />
        <property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
    </properties>
</persistence-unit>
</persistence>

invoke persistent follows

EntityManagerFactory enfactory = Persistence.createEntityManagerFactory("ProcedimientosAlmacenados");
    EntityManager enmanager = enfactory.createEntityManager();

I jump the following error

Caused by: javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML (line-1 : column -1): cvc-elt.1: Cannot find the declaration of element 'persistence'.

Help me please!!!

2 Answers2

5

This question was answered here

This is the summary. The problem is that you mix JPA 2.0 and JPA 2.1 notation

Either this

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
                                 http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
  version="2.1">

for JPA 2.1 or this

<persistence 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"
  version="2.0">

for JPA 2 but not a mix thereof.

See http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/index.html for details.

Community
  • 1
  • 1
Carlos Laspina
  • 2,013
  • 4
  • 27
  • 44
0

Your namespace declaration is wrong.

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">
    ...
</persistence>

source: JSR-338

SubOptimal
  • 22,518
  • 3
  • 53
  • 69
  • the review and is equal to that you send me only change the order – William Morales Dec 14 '15 at 14:42
  • @WilliamMorales Sorry my mistake. Incomplete copied your declaration for comparision. Could it be that you rather need to use `JPA 2.0` instead? See the answer from "claspina". What hibernate version do you use? JPA 2.1 is supported only by version >= 4.3.11. – SubOptimal Dec 14 '15 at 14:53