0

我在构建 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");
4

1 回答 1

0

不要认为你应该使用 RESOURCE_LOCAL 事务类型,使用 JTA。试试看这里:“jta-datasource”和“resource-local”数据源之间的区别?

于 2013-09-02T11:32:31.500 回答