没有名为“ my PU Name”的EntityManager的持久性提供程序

时间:2018-06-19 14:34:54

标签: hibernate jpa

我搜索了所有选项,但现在对我没有任何帮助。 我遇到了创建数据库表的问题

  

线程“ main”中的异常javax.persistence.PersistenceException:名为FinanceiroPU的EntityManager的持久性提供程序没有       在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)       在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)       在com.ronaldosistemas.financeiro.factory.CriaTabelas.main(CriaTabelas.java:9)

这是我的CriaTabelas.Java

package com.ronaldosistemas.financeiro.factory;

import javax.persistence.Persistence;

public class CriaTabelas {

    public static void main(String[] args) {

        Persistence.createEntityManagerFactory("FinanceiroPU");

    }
}

这是我的persistense.xml及其位置

<persistence-unit name="FinanceiroPU">
    <!-- Implementação do JPA, no nosso caso Hibernate -->
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/financeiro" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="" />
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.hbm2ddl.auto" value="update" />
    </properties>
</persistence-unit>

persistence location

最后是我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ronaldosistemas</groupId>
<artifactId>financeiro</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependencies>
    <!-- OmniFaces (utilitarios para JSF) -->
    <dependency>
        <groupId>org.omnifaces</groupId>
        <artifactId>omnifaces</artifactId>
        <version>2.0</version>
        <scope>compile</scope>
    </dependency>

    <!-- PrimeFaces (biblioteca de componentes) -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.1</version>
        <scope>compile</scope>
    </dependency>

    <!-- Weld (implementação do CDI) -->
    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>2.2.9.Final</version>
        <scope>compile</scope>
    </dependency>

    <!-- Weld depende do Jandex -->
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jandex</artifactId>
        <version>1.2.3.Final</version>
        <scope>compile</scope>
    </dependency>

    <!-- Implementacao do Bean Validation -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.1.3.Final</version>
        <scope>compile</scope>
    </dependency>

    <!-- Núcleo do Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.8.Final</version>
        <scope>compile</scope>
    </dependency>

    <!-- Implementação de EntityManager da JPA -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.8.Final</version>
        <scope>compile</scope>
    </dependency>

    <!-- Driver JDBC do MySQL -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.34</version>
        <scope>compile</scope>
    </dependency>

    <!-- Mojarra (implementacao do JSF) -->
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.2.10</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

我关闭了提供程序,并更新了我的sql连接器和休眠持久性jar,但仍然无法正常工作

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

请有人可以帮助我吗?非常感谢

1 个答案:

答案 0 :(得分:0)

我的问题在交易persistense.xml头后已经解决。 我认为我使用的是旧版本

在正确的

;