1

I know the question have been asked a lot of time but i can't find what i've done wrong...

I'm trying to transform my java web project into a maven project ... And when I start it got this error and i can't find why :

javax.persistence.PersistenceException: No Persistence provider for EntityManager named calamar

Here is my pom.xml :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>fr.airfrance</groupId>
    <artifactId>calamar</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>calamar Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.2.2.Final</version>
        </dependency>

        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901-1.jdbc4</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>calamar</finalName>
    </build>
</project>

And my persistance.xml :

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="calamar" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>beans.Application</class>
        <class>beans.Derogation</class>
        <class>beans.DerogationFille</class>
        <class>beans.DerogationAutre</class>
        <class>beans.DerogationLinux</class>
        <class>beans.DerogationOracle</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
            <property name="hibernate.id.new_generator_mappings" value="false"/>
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
            <property name="hibernate.connection.url" value="..."/>
            <property name="hibernate.connection.username" value="..."/>
            <property name="hibernate.connection.password" value="..."/>
        </properties>
    </persistence-unit>
</persistence>

I've put my persistence.xml in this eclipse folder :

Java Resources/src/main/resources/persistence.xml

Can someone help me please ?

Prasad Kharkar
  • 13,410
  • 5
  • 37
  • 56
Antoine Grenard
  • 1,712
  • 3
  • 21
  • 41

1 Answers1

2

Try putting your persistence.xml inside the META-INF folder:

Java Resources/src/main/resources/META-INF/persistence.xml

Thogor
  • 321
  • 2
  • 7
  • 1
    If your packaging everything directly in your war file, I think you can add it directly to your WEB-INF folder like so: Java Resources/src/main/webapp/WEB-INF/classes/META-INF/persistence.xml – Thogor Aug 25 '16 at 08:13
  • 1
    Could you give some more information about your project structure then? Is this one module or the web module of a multi-module maven project? If possible, add the module/directory structure of your project to the question. – Thogor Aug 25 '16 at 08:43
  • And maybe add content of you lib folder, maybe Eclipse missing some jars – Hrabosch Aug 25 '16 at 08:45
  • I've found the way to make it work ... (finally) As you said Hrabosch, i did import the jar in my buid path as you said Thogor i put the persistence.xml directly in Deplyed Resources/webapp/WEB-INF/classes/META-INF – Antoine Grenard Aug 25 '16 at 09:05