没有为EntityManager命名的持久性提供程序

时间:2016-08-25 07:43:10

标签: java hibernate maven jpa

我知道问题已被问了很多时间,但我找不到我做错了什么......

我正在尝试将我的java web项目转换为maven项目...... 当我开始它有这个错误,我找不到原因:

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

这是我的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>

我的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>

我把我的persistence.xml放在这个eclipse文件夹中:

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

是的,有人能帮帮我吗?

1 个答案:

答案 0 :(得分:2)

尝试将persistence.xml放在META-INF文件夹中:

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