Bezdepbonusu7Программирование: статьи и ответы

Вопрос

Не удается найти объявление элемента "постоянство"

Автор вопроса: William MoralesОтветов: 2

у меня следующая настойчивость

Есть фрагмент кода:

<?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
EntityManagerFactory enfactory = Persistence.createEntityManagerFactory("ProcedimientosAlmacenados");
    EntityManager enmanager = enfactory.createEntityManager();
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>

вызывать постоянные подписки

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

Я прыгаю со следующей ошибкой

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

Помоги мне, пожалуйста!!!

  • есть закрывающий тег для persistence ? corn3lius 14.12.2015

javahibernatejtaswitchyard

Ответы

Ответ 1 · рейтинг 5 · Carlos Laspina

Ответ на этот вопрос был дан здесь

Это резюме. Проблема в том, что вы смешиваете нотацию JPA 2.0 и JPA 2.1.

Либо это

<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
<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">
1.xsd" version="2.1">

для JPA 2.1 или этого

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

для JPA 2, но не их смесь.

См. http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/index.html для получения подробной информации.

Ответ 2 · SubOptimal

Ваше объявление пространства имен неверно.

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

источник: JSR-338

Перевод вопроса и ответов сообщества Stack Overflow, лицензия CC BY-SA. Оригинал на Stack Overflow.

Похожие материалы