JPA with TopLink: META-INF / persistence.xml not found in classpath

public class LoginTest { public static void main(String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("IRCBotPU"); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); Login lg = new Login(); lg.setPassword("password"); lg.setUserName("Rocky"); em.persist(lg); em.flush(); Login st = em.find(Login.class, lg.getPassword()); System.out.println(st); em.getTransaction().commit(); em.close(); emf.close(); } } 

I get an exception when I try to run this class

 javax.persistence.PersistenceException: No Persistence provider for EntityManager named IRCBotPU: No META-INF/persistence.xml was found in classpath. 

META-INF / persistence.xml is in my classpath. I do not know what is the reason or this exception.

The Persistence Library is TopLink.

+8
java classpath jpa toplink persistence
Aug 14 '09 at 17:20
source share
7 answers

I had the same problem, I saved the persistence.xml file in the WebContent / META-INF directory, and the jpa specification:
The root element of the save unit is the WEB-INF / classes directory; the persistence.xml file is therefore contained in the WEB-INF / classes / META-INF directory
try putting persistence.xml under src / META-INF.

+22
Mar 11
source share

The error is somewhat misleading. the XML file itself must not be in the classpath; the part of the message "META-INF / persistence.xml" means that the directory containing META-INF / persistence.xml should be.

If your hard drive had the following

C: \ LIES \ JPA \ META-INF \ persistence.xml

then your class path should include this

 CLASSPATH=c:\libs\JPA 

If META-INF \ Persistence.xml was contained in foo.jar, assuming META-INF / Persistence.xml is located in the root jar folder, your class path should have this

 CLASSPATH=C:\<path to jar>\foo.jar 

This may seem obvious or redundant, but my goal is to make sure that we compare apples to apples, and CLASSPATH, along with loading classes, can be a crawler.

So can you post your CLASSPATH?

+2
Aug. 14 '09 at 20:08
source share

If you use intellij or the maven project structure, you need to put the entire file "META-INF / persistance.xml" in the "Resources" folder (src / resources) so that it moves your persistence.xml file to "WEB-INF / classes / persistence.xml ".

if you use eclipse or something else, make the appropriate changes so that it moves the file to WEB-INF / classes / persistence.xml "

nothing worked for me.

+2
Apr 04 '16 at 21:52
source share

persistence.xml should not be in your classpath; The JAR file containing persistence.xml in its META-INF folder should.

+1
Aug 14 '09 at 17:27
source share

I have a web application and everything is working fine. What I did was add the META-INF directory with the persistence.xml file to the src / main / resources directory [Maven project]

+1
Mar 06 '12 at 8:15
source share

Your META-INF / persistence.xml file should look something like this:

 // <persistence> // <persistence-unit name="IRCBotPU"> // <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider> // <!-- All persistence classes must be listed --> // <class>entity.Customer</class> // <class>entity.Order</class> // <class>entity.Item</class> // <properties> // <!-- Provider-specific connection properties --> // <property name="toplink.jdbc.driver" value="<database driver>"/> // <property name="toplink.jdbc.url" value="<database url>"/> // <property name="toplink.jdbc.user" value="<user>"/> // <property name="toplink.jdbc.password" value="<password>"/> // <!-- Provider-specific settings --> // <property name="toplink.logging.level" value="INFO"/> // </properties> // </persistence-unit> // </persistence> 

The attribute of your persistence-unit attribute in your persistence.xml file does not match the value you pass to the Persistence.createEntityManagerFactory method. Make sure your persistence unit name is set to "IRCBotPU".

0
Aug 14 '09 at 17:49
source share

I created a folder programmed by META-INF under src and it works. "marcosbeirigo" has answered this already. I do not know why I should put persistance.xml there. I put it under WebContent / META-INF and did not work

0
Dec 06 '13 at 16:56
source share



All Articles