问题
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) ...
Application config class
@Configuration
@EnableJpaRepositories(repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@EnableTransactionManagement
public class ApplicationConfig {}
Entity class
@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 {}
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"
)
回答1:
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.
Make sure that both hibernate-core
and hibernate-envers
reference the same version.
来源:https://stackoverflow.com/questions/41289750/spring-data-envers-hibernate-java-lang-nosuchmethoderror-org-hibernate-engine-s