gpt4 book ai didi

hibernate - 无法在Gradle项目中配​​置EntityManagerFactory

转载 作者:行者123 更新时间:2023-12-03 06:23:55 25 4
gpt4 key购买 nike

构建gradle项目时出现以下问题:

[main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
[main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.7.Final
[main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
[main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
[main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
[main] INFO org.hibernate.ejb.Version - Hibernate EntityManager 3.6.7.Final
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: WebSISMSPUpgsql] Unable to configure EntityManagerFactory
....
Caused by: org.hibernate.MappingException: Unable to instantiate specified event (post-insert) listener class: org.hibernate.envers.event.AuditEventListener
...
Caused by: java.lang.ClassNotFoundException: org.hibernate.envers.event.AuditEventListener

我的build.gradle
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'war'
mainClassName = "main.Main"
sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
sourceCompatibility = '1.6'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

if (!hasProperty('mainClass')) {
ext.mainClass = 'main.Main'
}

repositories {
mavenCentral()
}

dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '3.6.7.Final'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.5'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.5'
compile 'postgresql:postgresql:9.1-901-1.jdbc4'
compile "javax.ws.rs:jsr311-api:1.1.1"
compile 'com.sun.jersey:jersey-server:1.13'
compile 'com.sun.jersey:jersey-core:1.13'
compile 'com.sun.jersey:jersey-servlet:1.13'
testCompile group: 'junit', name: 'junit', version: '4.10'
runtime group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
runtime group: 'org.hibernate', name: 'hibernate-entitymanager', version: '3.6.7.Final'
}

我的/resources/META-INF/persistence.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="WebSISMSPUpgsql" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>jpa.Routes</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
<property name="hibernate.connection.username" value="postgres"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.password" value="postgres"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postgres"/>
<property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener"/>
</properties>
</persistence-unit>

异常显示,当我试图在主类中运行时:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("WebSISMSPUpgsql");

最佳答案

不要认为您应该使用RESOURCE_LOCAL事务类型,请使用JTA。尝试在这里查看:Difference between a "jta-datasource" and a " resource-local " datasource?

关于hibernate - 无法在Gradle项目中配​​置EntityManagerFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18572064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com