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'm getting 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 don't know what is the reason or this exception.
Persistence library is TopLink.
I had the same problem, i was keeping my persistence.xml file in the WebContent/META-INF directory, while the jpa specification says:
the root of the persistence unit is the WEB-INF/classes directory; the persistence.xml file is therefore contained in the WEB-INF/classes/META-INF directory
try placing persistence.xml under src/META-INF.
if you are using IntelliJ
or a maven project structure you need to place the entire "META-INF/persistence.xml"
file in the in resources(src/resources) folder so that it will move your persistence.xml
file into "WEB-INF/classes/persistence.xml"
location.
if you are using eclipse
or something else makes the changes accordingly so that it will move the file to WEB-INF/classes/persistence.xml
anything else did not work for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With