【问题标题】:Cannot find the declaration of element 'persistence' [duplicate]找不到元素“持久性”的声明 [重复]
【发布时间】:2016-03-20 01:26:10
【问题描述】:

我有以下坚持

有一个代码sn-p:

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

请帮帮我!!!

【问题讨论】:

  • persistence 是否有结束标签?

标签: java hibernate jta switchyard


【解决方案1】:

此问题已回答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

【讨论】:

  • 这是使用JPA 2.1的愿望,我觉得和我的坚持没有区别
  • 你能帮我做一些更具体的事情吗?请不要遇到问题
  • 我为此苦苦挣扎了大约半天,您的回答在我指定 JPA 2.1 时有所帮助,但结果证明 Eclipse 或 JPA 方面需要 JPA 2.0 O_o
【解决方案2】:

您的命名空间声明错误。

<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

【讨论】:

  • 评论等于你发给我只改订单
  • @WilliamMorales 对不起我的错误。 Incomplete 复制了您的声明以供比较。是不是你宁愿需要使用JPA 2.0 来代替?请参阅“claspina”的答案。你用的是什么休眠版本? JPA 2.1 仅受版本 >= 4.3.11 支持。
猜你喜欢
  • 2021-05-18
  • 2014-01-16
  • 2012-01-08
  • 2017-02-06
  • 1970-01-01
  • 2016-09-09
  • 1970-01-01
  • 2020-11-09
  • 2012-07-02
相关资源
最近更新 更多