本文介绍了spring-data-envers Hibernate java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionImplementor.getTransactionCoordinator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Spring boot 1.4.2 application with Hibernate 5.2.2 and Spring data Envers 1.0.5. Entities are persisted fine when they are not audited. Annotating the entities with @Audited results in a transaction rollback with the following stacktrace. Any ideas?

> 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 构建文件中的相关片段

Relevant snippets from gradle build file

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"
        )

推荐答案

看起来您在 gradle 配置中指定了 5.2.2.Final 的休眠版本,但我没有查看您在哪里覆盖 Envers 的默认版本,因此 spring 模块可能会为 Envers 导入 4.3.11.Final,从而造成您看到的冲突.

It looks like you're specifying the hibernate version of 5.2.2.Final in your gradle configuration, but I don't see where you're overwriting the default version for Envers, so chances are the spring module may be importing 4.3.11.Final for Envers, creating the conflicts you see.

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

Make sure that both hibernate-core and hibernate-envers reference the same version.

这篇关于spring-data-envers Hibernate java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionImplementor.getTransactionCoordinator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:23