spring-data-envers Hibernate java.lang.NoSuchMethodError:org.hibernate.engine.spi.SessionImplementor.getTransactionCoordinator

时间:2016-12-22 18:39:02

标签: spring-boot spring-data spring-data-jpa hibernate-envers

我有一个带有Hibernate 5.2.2和Spring数据Envers 1.0.5的Spring boot 1.4.2应用程序。实体在未经审核时保持良好状态。使用@Audited注释实体会导致使用以下堆栈跟踪进行事务回滚。有什么想法吗?

> 2016-12-22 18:15:08,364 ERROR | http-nio-8080-exec-1 |
> org.springframework.orm.jpa.JpaTransactionManager       | Commit
> exception overridden by rollback exception 
> java.lang.NoSuchMethodError:
> org.hibernate.engine.spi.SessionImplementor.getTransactionCoordinator()Lorg/hibernate/resource/transaction/TransactionCoordinator;
> at
> org.hibernate.envers.internal.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:131)
> at
> org.hibernate.envers.internal.synchronization.AuditProcessManager$1.doBeforeTransactionCompletion(AuditProcessManager.java:46)
> at
> org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:928)
> at
> org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:503)
> at
> org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2383)
> at
> org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
> at
> org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
> at
> org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
> at
> org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:220)
> at
> org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
> at
> org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
> at
> org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
> at
> org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
> at
> org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)
> at
> org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
> at
> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
> at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
> at
> org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
> at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
> at
> org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)
> at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
> at
> org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
> at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
> at
> org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
> at com.sun.proxy.$Proxy173.save(Unknown Source) ...

应用程序配置类

@Configuration
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@EnableTransactionManagement
public class ApplicationConfig {}

实体类

@Entity(name = "foo")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "sub_type", discriminatorType = DiscriminatorType.INTEGER)
@Table(name = "foo")
@SecondaryTable(
        name = "bar",
        pkJoinColumns = @PrimaryKeyJoinColumn(name = "foo_id"))
@Audited
public class FooEntity {}

来自gradle构建文件的相关代码段

buildscript {
    ext {
        springBootVersion = "1.4.2.RELEASE"
        verifier_version = "1.0.0.RELEASE"
    }
    repositories {
        maven {url "https://plugins.gradle.org/m2/"}
        maven {url "http://repo.spring.io/plugins-release"}
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.build.gradle:propdeps-plugin:0.0.7") 
        classpath("io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE")
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("se.transmode.gradle:gradle-docker:1.2")
        classpath("com.commercehub:gradle-cucumber-jvm-plugin:0.7")
        classpath("org.ajoberstar:grgit:1.1.0")
        classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.1-rc3")
        classpath("gradle.plugin.org.detoeuf:swagger-codegen-plugin:1.6.3")
        classpath("org.springframework.cloud:spring-cloud-contract-gradle-plugin:${verifier_version}")
        classpath "net.linguica.gradle:maven-settings-plugin:0.5"
    }
}
...
dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.SR7"
        mavenBom "org.springframework.cloud:spring-cloud-contract-dependencies:${verifier_version}"
        mavenBom 'org.springframework.cloud:spring-cloud-stream-dependencies:Brooklyn.SR1'
    }
}
... 
   compile(
                "org.springframework.boot:spring-boot-starter-data-jpa",
                'org.springframework.data:spring-data-commons',
                'org.springframework.cloud:spring-cloud-starter-config',
                'org.springframework.cloud:spring-cloud-starter-eureka',
                'org.springframework.cloud:spring-cloud-starter-sleuth',
                'org.springframework.cloud:spring-cloud-sleuth-zipkin',
                'com.netflix.hystrix:hystrix-javanica',
                'org.springframework.boot:spring-boot-starter-aop',
                "org.springframework.boot:spring-boot-starter-web",
                "io.swagger:swagger-annotations:1.5.9",
                "com.google.code.gson:gson:2.7",
                "gradle.plugin.org.detoeuf:swagger-codegen-plugin:1.6.3",
                "org.springframework:spring-orm",
                "com.oracle.jdbc:ojdbc7:12.1.0.2",
                'org.springframework.cloud:spring-cloud-stream',
                'org.springframework.cloud:spring-cloud-stream-test-support',
                'org.springframework.cloud:spring-cloud-stream-binder-test',
                "org.springframework.boot:spring-boot-starter-hateoas",
                "com.fasterxml.jackson.module:jackson-module-parameter-names",
                "com.fasterxml.jackson.datatype:jackson-datatype-jdk8",
                "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.1",
                "org.hibernate:hibernate-core:5.2.2.Final",
                "org.springframework.data:spring-data-envers:1.0.5.RELEASE"
        )

1 个答案:

答案 0 :(得分:4)

看起来你在gradle配置中指定了5.2.2.Final的hibernate版本,但是我没有看到你在哪里覆盖了Envers的默认版本,所以spring模块可能正在导入对于Envers,4.3.11.Final,创建您看到的冲突。

确保hibernate-corehibernate-envers引用相同的版本。