首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到元素“persistence”的声明,缺少元素持久性

找不到元素“persistence”的声明,缺少元素持久性
EN

Stack Overflow用户
提问于 2021-02-16 01:46:45
回答 1查看 50关注 0票数 0

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

代码语言:javascript
复制
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'

这是我的文件:

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2021-02-16 18:59:27

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

persistence.xml文件定义持久性单元。persistence.xml文件位于持久性单元根目录的META-INF目录中。

因此,尝试将您的persistence.xml放在META-INF目录中。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66212927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档