无法解析 class 'HibernatePersistenceProvider'
Cannot resolve class 'HibernatePersistenceProvider'
我在 build.gradle 中有休眠依赖项,但我收到以下错误
> Task :JPABootstrapping.main() FAILED
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named recipes
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at setup.JPABootstrapping.main(JPABootstrapping.java:10)
Execution failed for task ':JPABootstrapping.main()'.
> Process 'command '/usr/lib/jvm/java-14-openjdk-amd64/bin/java'' finished with non-zero exit value 1
persistence.xml
在src/main/resources/META-INF
下
<persistence>
<persistence-unit name="recipes">
<description>Hibernate Tips</description>
<provider>
org.hibernate.jpa.HibernatePersistenceProvider
</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL81Dialect" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://192.168.122.242:5432/recipes" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="postgres" />
</properties>
</persistence-unit>
</persistence>
IntelliJ 的检查功能说 HibernatePersistenceProvider
无法解析:
build.gradle
如下,包含hibernate核心和postgresql驱动依赖:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.0.5.Final'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.18'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
那个 hibernate-core
真的很古老,更准确地说它是在 2015 年发布的。那个神器不包含 org.hibernate.jpa.HibernatePersistenceProvider
class。从那以后,Hibernate 被重新命名和重构了很多。
最新稳定版是:
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.4.26.Final'
而这个工件有那个 class。
附加信息:Hibernate 将再次重命名。新坐标将:
implementation group: 'org.hibernate.orm', name: 'hibernate-core', version: '6.0.0.Final'
.
我在 build.gradle 中有休眠依赖项,但我收到以下错误
> Task :JPABootstrapping.main() FAILED
Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named recipes
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at setup.JPABootstrapping.main(JPABootstrapping.java:10)
Execution failed for task ':JPABootstrapping.main()'.
> Process 'command '/usr/lib/jvm/java-14-openjdk-amd64/bin/java'' finished with non-zero exit value 1
persistence.xml
在src/main/resources/META-INF
下
<persistence>
<persistence-unit name="recipes">
<description>Hibernate Tips</description>
<provider>
org.hibernate.jpa.HibernatePersistenceProvider
</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL81Dialect" />
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://192.168.122.242:5432/recipes" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="postgres" />
</properties>
</persistence-unit>
</persistence>
IntelliJ 的检查功能说 HibernatePersistenceProvider
无法解析:
build.gradle
如下,包含hibernate核心和postgresql驱动依赖:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.0.5.Final'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.18'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
那个 hibernate-core
真的很古老,更准确地说它是在 2015 年发布的。那个神器不包含 org.hibernate.jpa.HibernatePersistenceProvider
class。从那以后,Hibernate 被重新命名和重构了很多。
最新稳定版是:
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.4.26.Final'
而这个工件有那个 class。
附加信息:Hibernate 将再次重命名。新坐标将:
implementation group: 'org.hibernate.orm', name: 'hibernate-core', version: '6.0.0.Final'
.