java - 找不到元素 'persistence' 的声明

标签 java hibernate jta switchyard

<分区>

我有以下的坚持

有一段代码:

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

调用持久跟随

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

请帮帮我!!!

最佳答案

这个问题得到了回答here

这是总结。问题是您混合了 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_2_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了解详情。

关于java - 找不到元素 'persistence' 的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34269169/

相关文章:

java - 在 Brian Goetz 的 Concurrency In Practice 中,为什么可伸缩缓存的最后一个例子中有 while(true)?

java - 双向一对多,一方为拥有方

java - 混合 JTA 和 JDBC 事务

java - 如果围绕操作类创建代理建议,Spring Web 应用程序上下文不会返回 Struts2 操作方法

java - 在 Java 中加密/解密 "AES/ECB/PKCS5Padding"

java - 使用 Hibernate 映射 ArrayList

java - 管理交易的最佳方式

java - 通过 Payara 4 诊断与 Oracle 的 XA 连接

java - 有没有更好的方法将日历日期归零?

java - Hibernate GenerationType.IDENTITY 与 GenerationType.SEQUENCE