After thoroughly searching this forums looking for an answer, I couldn't find a single case similar to mine.
After generating the WAR filer using maven and deploying my server, everytime I send a GET request to a API that needs to create a DAO I get the following warning on the server console:
Could not find any META-INF/persistence.xml file in the classpath
and the following exception:
No Persistence provider for EntityManager named mim_ajuda
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="mim_ajuda" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/mim_ajuda" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="B@ck3nd" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<!-- Configuring Connection Pool -->
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="20" />
<property name="hibernate.c3p0.timeout" value="500" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="2000" />
</properties>
</persistence-unit>
</persistence>'
on this section of the code:
private EntityManager getEntityManager(){
EntityManagerFactory factory = Persistence
.createEntityManagerFactory("mim_ajuda");
if(entityManager == null){
entityManager = factory.createEntityManager();
}
return entityManager;
}
Before I can go with this further, I have already searched the where to put the persistence.xml and according to THIS page and several other users, the XML must be in the "WEB-INF/classes/META-INF/persistence.xml" directory inside a the war file (which mine is):
To summarize:
- The automated test work just fine running offline and using the entityManager
- Only when I call the webservice API that I get this error
- The persinstence.xml file follows the path shown in other questions.