我将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>发布于 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目录的类路径中的某个位置。
https://stackoverflow.com/questions/66212927
复制相似问题