No Persistence provider for EntityManager named

前端 未结 30 1902
甜味超标
甜味超标 2020-11-22 03:45

I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with:

相关标签:
30条回答
  • 2020-11-22 04:30

    Corner case: if you are using m2Eclipse, it automatically puts in excludes on your resources folders. Then when you try to run tests inside eclipse, the subsequent absence of persistence.xml will produce this error.

    0 讨论(0)
  • 2020-11-22 04:30

    I faced the same problem, but on EclipseLink version 2.5.0.

    I solved my problem by adding yet another jar file which was necessarily (javax.persistence_2.1.0.v201304241213.jar.jar);

    Jars needed:
    - javax.persistence_2.1.0.v201304241213.jar
    - eclipselink.jar
    - jdbc.jar (depending on the database used).

    I hope this helps.

    0 讨论(0)
  • 2020-11-22 04:32

    You need the following jar files in the classpath:

    1. antlr-2.7.6.jar
    2. commons-collections-3.1.jar
    3. dom4j-1.6.1.jar
    4. hibernate-commons-annotations-4.0.1.Final.jar
    5. hibernate-core-4.0.1.Final.jar
    6. hibernate-entitymanager.jar
    7. hibernate-jpa-2.0-api-1.0.0.Final.jar
    8. javassist-3.9.0.jar
    9. jboss-logging-3.1.1.GA.jar
    10. jta-1.1.jar
    11. slf4j-api-1.5.8.jar
    12. xxx-jdbc-driver.jar
    0 讨论(0)
  • 2020-11-22 04:32

    In my case, previously I use idea to generate entity by database schema, and the persistence.xml is automatically generated in src/main/java/META-INF,and according to https://stackoverflow.com/a/23890419/10701129, I move it to src/main/resources/META-INF, also marked META-INF as source root. It works for me.

    But just simply marking original META-INF(that is, src/main/java/META-INF) as source root, doesn't work, which confuses me.

    and this is the structre:

    0 讨论(0)
  • 2020-11-22 04:33

    Faced the same issue and couldn't find solution for quite a long time. In my case it helped to replace

    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    

    with

    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    

    Took solution from here

    0 讨论(0)
  • 2020-11-22 04:34

    Maybe you defined one provider like <provider>org.hibernate.ejb.HibernatePersistence</provider> but referencing another one in jar. That happened with me: my persistence.xml provider was openjpa but I was using eclipselink in my classpath. Hope this help!

    0 讨论(0)
提交回复
热议问题