I have my persistence.xml
with the same name using TopLink
under the META-INF
directory.
Then, I have my code calling it with:
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.
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.
You need the following jar files in the classpath:
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:
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
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!