I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with:
private static EntityManagerFactory entityManagerFactory;
private static final String PERSISTENCE = "PERSISTENCE";
public static EntityManagerFactory getEntityManagerFactory() {
if (entityManagerFactory == null) {
entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE);
}
return entityManagerFactory;
}
Yet, I got the following error message:
Exception in thread "main" java.lang.ExceptionInInitializerError
at MainApp.initAccountCategory(MainApp.java:84)
at MainApp.main(MainApp.java:25)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named PERSISTENCE at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at util.HibernateUtil.getEntityManagerFactory(HibernateUtil.java:16) at common.AppContext.(AppContext.java:34)
Here is the persistence.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_2.xsd
http://xmlns.jcp.org/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd"
version="2.2">
<persistence-unit name="PERSISTENCE">
<description>bank simulation application</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/bankmodul"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="Mahdi@123"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>