1
votes

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):

WAR directory Image

To summarize:

  1. The automated test work just fine running offline and using the entityManager
  2. Only when I call the webservice API that I get this error
  3. The persinstence.xml file follows the path shown in other questions.
1

1 Answers

1
votes

Found a solution. The parsers is CASE SENSITIVE, therefore my Persistance.xml could not me found. Rename to persistance.xml and you will be fine