相关疑难解决方法(0)

JPA 2.0使用Hibernate作为提供程序 - 例外:没有EntityManager的持久性提供程序

我正在尝试通过遵循Hibernate EntityManager 文档中的信息来设置一个简单的jpa 2.0项目.我已经在这几个小时了,但无论我做什么,当我尝试创建一个EntityManagerFactory时,我总是得到这个异常:

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named manager1
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
    at se.mycomp.UserTest.main(UserTest.java:9)
Run Code Online (Sandbox Code Playgroud)

我发现了很多关于这个例外的类似问题,但没有我能够解决的解决方案.我在这做错了什么?

目录结构

.
??? pom.xml
??? src
    ??? main
    ?   ??? java
    ?   ?   ??? se
    ?   ?       ??? mycomp
    ?   ?           ??? UserTest.java
    ?   ?           ??? domain
    ?   ?               ??? User.java
    ?   ??? resources
    ?       ??? META-INF
    ?       ?   ??? persistence.xml
    ?       ??? log4j.properties
    ??? test
        ??? java
Run Code Online (Sandbox Code Playgroud)

我的persistence.xml

<persistence 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"
             version="2.0"> …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa maven

26
推荐指数
1
解决办法
8万
查看次数

Hibernate 5.2.2:没有EntityManager的持久性提供程序

Hibernate 5.1.1和5.2.2之间有什么变化?如果我使用5.2.2,我将收到一条错误消息"没有为EntityManager命名为pu的持久性提供程序".完全相同的配置适用于5.1.1.我应该如何更改代码以使5.2.2工作?

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>jpatest</groupId>
    <artifactId>jpatest</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <hibernate.version>5.2.2.Final</hibernate.version>
    </properties>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4.1209.jre7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

src/main/resources/META-INF中的persistence.xml

<?xml version="1.0" encoding="UTF-8" ?>
<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"
    version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="pu" >
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <properties>
            <property name="hibernate.archive.autodetection" value="class" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
            <property name="hibernate.connection.url" …
Run Code Online (Sandbox Code Playgroud)

java hibernate

23
推荐指数
1
解决办法
3万
查看次数

标签 统计

hibernate ×2

java ×2

jpa ×1

maven ×1