2021年4月11日星期日

cvc-elt.1.a:, Can not find the declaration of element 'persistence'

Here is my persistence.xml:

<?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="PU" transaction-type="RESOURCE_LOCAL">          <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>          <exclude-unlisted-classes>false</exclude-unlisted-classes>          <properties>              <property name="javax.persistence.jdbc.url"     value="jdbc:sqlserver://localhost:1433;databaseName=SocialDB"/>              <property name="javax.persistence.jdbc.user" value="ramy"/>              <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>              <property name="javax.persistence.jdbc.password" value="%=4b[E6c"/>              <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>          </properties>      </persistence-unit>  </persistence>  

And here is the error:

Root Cause    javax.persistence.PersistenceException: Invalid persistence.xml.  Error parsing XML (line-1 : column -1): cvc-elt.1.a: Cannot find the declaration of element 'persistence'.    org.hibernate.ejb.packaging.PersistenceXmlLoader.loadURL(PersistenceXmlLoader.java:147)  org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:171)  org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:326)  org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:58)  javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)  javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)  bo.MyEntityManagerFactory.getEntityManager(MyEntityManagerFactory.java:22)  bo.UserHandler.getAllUsers(UserHandler.java:106)  bo.UserHandler.getAllUserViewsTrimmed(UserHandler.java:88)  

I receive this error once upon starting the server as well as each time I perform a database query.

Edit: Here are my (Maven) dependencies (The project is a web microservice that interfaces with an MSSQL database using Hibernate, and uses jersey framework to convert from/to JSON object in order to read to/write from the aforementioned database):

<groupId>com.fasterxml.jackson.core</groupId>          <artifactId>jackson-databind</artifactId>          <version>2.10.1</version>          <type>jar</type>      </dependency>        <dependency>          <groupId>org.glassfish.jersey</groupId>          <artifactId>project</artifactId>          <version>2.26</version>          <type>pom</type>      </dependency>      <dependency>          <groupId>org.glassfish.jersey.containers</groupId>          <artifactId>jersey-container-servlet</artifactId>          <version>2.26</version>      </dependency>      <dependency>          <groupId>org.glassfish.jersey.core</groupId>          <artifactId>jersey-client</artifactId>          <version>2.26</version>      </dependency>          <dependency>          <groupId>org.glassfish.jersey.core</groupId>          <artifactId>jersey-server</artifactId>          <version>2.26</version>      </dependency>            <dependency>          <groupId>org.glassfish.jersey.core</groupId>          <artifactId>jersey-common</artifactId>          <version>2.26</version>      </dependency>      <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->      <dependency>          <groupId>javax.persistence</groupId>          <artifactId>javax.persistence-api</artifactId>          <version>2.2</version>      </dependency>          <!-- https://mvnrepository.com/artifact/javax/javaee-web-api -->      <dependency>          <groupId>org.eclipse.persistence</groupId>          <artifactId>org.eclipse.persistence.core</artifactId>          <version>2.5.2</version>      </dependency>      <dependency>          <groupId>org.eclipse.persistence</groupId>          <artifactId>org.eclipse.persistence.asm</artifactId>          <version>2.5.2</version>      </dependency>      <dependency>          <groupId>org.eclipse.persistence</groupId>          <artifactId>org.eclipse.persistence.antlr</artifactId>          <version>2.5.2</version>      </dependency>      <dependency>          <groupId>org.eclipse.persistence</groupId>          <artifactId>org.eclipse.persistence.jpa</artifactId>          <version>2.5.2</version>      </dependency>      <dependency>          <groupId>org.eclipse.persistence</groupId>          <artifactId>org.eclipse.persistence.jpa.jpql</artifactId>          <version>2.5.2</version>      </dependency>      <dependency>          <groupId>org.eclipse.persistence</groupId>          <artifactId>javax.persistence</artifactId>          <version>2.1.0</version>      </dependency>      <dependency>          <groupId>org.eclipse.persistence</groupId>          <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>          <version>2.5.2</version>          <scope>provided</scope>      </dependency>      <dependency>          <groupId>javax</groupId>          <artifactId>javaee-web-api</artifactId>          <version>7.0</version>          <scope>provided</scope>      </dependency>          <dependency>          <groupId>com.googlecode.json-simple</groupId>          <artifactId>json-simple</artifactId>          <version>1.1</version>      </dependency>        <dependency>          <groupId>org.glassfish.jersey.inject</groupId>          <artifactId>jersey-hk2</artifactId>          <version>2.26</version>      </dependency>      <dependency>          <groupId>org.hibernate</groupId>          <artifactId>hibernate-core</artifactId>          <version>4.3.0.Final</version>      </dependency>                    <dependency>          <groupId>org.hibernate</groupId>          <artifactId>hibernate-entitymanager</artifactId>          <version>4.3.0.Final</version>      </dependency>        <dependency>          <groupId>com.microsoft.sqlserver</groupId>          <artifactId>mssql-jdbc</artifactId>          <version>6.1.0.jre8</version>      </dependency>          
https://stackoverflow.com/questions/67048347/cvc-elt-1-a-can-not-find-the-declaration-of-element-persistence April 12, 2021 at 01:48AM

没有评论:

发表评论