EclipseLinke:No resource files named META-INF/services/javax.persistence.spi:No PersistenceProvider were found

南笙酒味 提交于 2019-12-02 02:18:39

问题


I am using EclipseLink and even I have all necessary jar files imported with maven, I get still the Exception:

Exception in thread "main" javax.persistence.PersistenceException: No resource files named META-INF/services/javax.persistence.spi.PersistenceProvider were found. Please make sure that the persistence provider jar file is in your classpath.

In Maven pom I have the dependency:

<dependency>
      <groupId>javax.persistence</groupId>
      <artifactId>persistence-api</artifactId>
      <version>1.0.2</version>
      <scope>provided</scope>
</dependency>

Here is my persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    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">
    <persistence-unit name="PersistenzJPAProjekt">
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>com.testJPABasis.Person</class>

    </persistence-unit>
</persistence>

Here the clathpath in eclipse:

The class which actually generates the exception:

public class TestJPA
{
    public static void main(String[] args)
    {
        Person person = new Person();
        person.setPersonID(1);

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersistenzJPAProjekt");
        EntityManager em = emf.createEntityManager();

    }
}

The persistence.xml is directly under META-INF. As far as I know I don't need to have Glassfish or Tomcat as EclipseLink is made for standalone applications. If I am wrong maybe this is then the cause. The Meta-Inf is placed in:


回答1:


persistence-api is just that: the API (mostly interfaces). You still need to include the actual persistence provider; it looks like you're wanting EclipseLink.



来源:https://stackoverflow.com/questions/18815133/eclipselinkeno-resource-files-named-meta-inf-services-javax-persistence-spino

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!