【问题标题】:Can not find the declaration of element 'persistence' , element persistence missing找不到元素“持久性”的声明,缺少元素持久性
【发布时间】:2021-05-18 15:05:36
【问题描述】:

已将persistence.xml 放在eclipse 中项目的类路径中,因为之前的错误是找不到文件。现在给出这个错误:

Caused by: javax.persistence.PersistenceException: Invalid persistence.xml. Error parsing XML [line : -1, column : -1] : cvc-elt.1: Can not find the declaration of element 'persistence'

这是我的文件:

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="2.1"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="DataSource" transaction-type="JTA">
        <description>JTA persistence unit related to the datasource DataSource</description>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.ejb.cfgfile" value="hibernate_DataSource.cfg.xml"/>
        </properties>
    </persistence-unit>

    <persistence-unit name="securityStore" transaction-type="JTA">
        <description>JTA persistence unit related to the datasource securityStore</description>
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
           <property name="hibernate.ejb.cfgfile" value="hibernate_securityStore.cfg.xml"/>
        </properties>
    </persistence-unit>
</persistence>

【问题讨论】:

标签: java hibernate jpa persistence


【解决方案1】:

根据 JPA 规范(参见第 8.2.1 节 persistence.xml 文件):

persistence.xml 文件定义了一个持久性单元。 persistence.xml文件位于持久化单元根目录META-INF目录下。

所以,试着把你的persistence.xml 放在META-INF 目录中。

附:也许您的应用程序实际上没有使用您所期望的 persistence.xml,而是放置在 META-INF 目录中的类路径中的某个位置。

【讨论】:

  • 事实上,我正在使用 Ireport 3.0.0,我在解析我的 persistence.xml 文件时遇到了困难,该文件适用于 jpa 2.1 版本(休眠 5.1.14-final)..so我的问题是 ireport 3.0.0 是否支持 jpa 2.1。如果不支持,还有其他解决方案吗?
  • 您好社区,我正在使用 Ireport 3.0.0,我在解析我的 persistence.xml 文件时遇到了困难,该文件适用于 jpa 2.1 版本(休眠 5.1.14-final)..so我的问题是 ireport 3.0.0 是否支持 jpa 2.1。如果不支持,还有其他解决方案吗?
猜你喜欢
  • 2014-01-16
  • 2012-01-08
  • 2017-02-06
  • 2016-03-20
  • 1970-01-01
  • 2016-09-09
  • 2016-03-18
  • 1970-01-01
  • 2011-05-25
相关资源
最近更新 更多