2
votes

I have a standard java application (not Java EE), and I'm trying to learn about JPA. The problem is that when I run the project, the console outputs:

1218 [main] INFO org.hibernate.ejb.Ejb3Configuration  - HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named entities
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
at com.svprdga.test.App.main(App.java:26)

So I figure that it's not finding my persistence.xml file, I've searched around and I see fixes which involves Java EE folders like WEB-INF, but that's not my case, also I've tried another solutions but the problem is still there.

I have persistence.xml in META-INF, under /src, and its content is:

<?xml version="1.0" encoding="UTF-8"?>
<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"
  version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="entities" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.svprdga.test.database.entity</class>
    <properties>

      <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/hibtest"/>
      <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="toplink.jdbc.user" value="root"/>
      <property name="toplink.jdbc.password" value=""/>

      <!-- EclipseLink should create the database schema automatically -->
      <property name="eclipselink.ddl-generation" value="create-tables" />
      <property name="eclipselink.ddl-generation.output-mode"
        value="database" />
    </properties>

  </persistence-unit>
</persistence>

Thanks for any help.

1
you seem to have a problem of knowing which JPA implementation to use. In one place you select Hibernate, then go about specifying lots of properties for TopLink, and then more properties for EclipseLink. I'd suggest you resolve which JPA provider you want to use before thinking moreDataNucleus
Of course; the problem is that when I try to use javax.persistence the console prompts me for a persistence provider; but I don't know what should I put in order to continue using javax.persistence.svprdga

1 Answers

9
votes

I found the solution, it appears that META-INF must be under src/main/resources if you are using Maven; then persistence.xml will be catched.