1

I have simple Spring Boot 2.5.7 JPA application and want audit diff between some entities

So my pom.xml include this dependency

<dependency>
  <groupId>org.javers</groupId>
  <artifactId>javers-spring-boot-starter-sql</artifactId>
  <version>6.5.1</version>
</dependency>

I tried config in applciation

javers:
  algorithm: levenshtein_distance
  dialect: POSTGRES

I created bean

  @Bean
  public Javers javers() {
    return JaversBuilder.javers()
        .withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
        .build();
  }

Also I tried add this annotation - JaversSpringDataAuditable

My service class

@Service
@RequiredArgsConstructor
public class TestService {

  private final Javers javers;
}

All I want is to know the difference between the two entities https://javers.org/documentation/diff-configuration/

But I keep getting the same error

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.javers.repository.sql.DialectName]: Factory method 'javersSqlDialectName' threw exception; nested exception is java.lang.ClassCastException: class jdk.proxy2.$Proxy204 cannot be cast to class org.hibernate.engine.spi.SessionFactoryImplementor (jdk.proxy2.$Proxy204 is in module jdk.proxy2 of loader 'app'; org.hibernate.engine.spi.SessionFactoryImplementor is in unnamed module of loader 'app')
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
    ... 62 common frames omitted
Caused by: java.lang.ClassCastException: class jdk.proxy2.$Proxy204 cannot be cast to class org.hibernate.engine.spi.SessionFactoryImplementor (jdk.proxy2.$Proxy204 is in module jdk.proxy2 of loader 'app'; org.hibernate.engine.spi.SessionFactoryImplementor is in unnamed module of loader 'app')
    at org.javers.spring.boot.sql.JaversSqlAutoConfiguration.javersSqlDialectName(JaversSqlAutoConfiguration.java:56)
    at org.javers.spring.boot.sql.JaversSqlAutoConfiguration$$EnhancerBySpringCGLIB$$e6ec8ead.CGLIB$javersSqlDialectName$0(<generated>)
    at org.javers.spring.boot.sql.JaversSqlAutoConfiguration$$EnhancerBySpringCGLIB$$e6ec8ead$$FastClassBySpringCGLIB$$466a8b80.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
    at org.javers.spring.boot.sql.JaversSqlAutoConfiguration$$EnhancerBySpringCGLIB$$e6ec8ead.javersSqlDialectName(<generated>)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 63 common frames omitted
LeshaRB
  • 1,345
  • 2
  • 23
  • 44

1 Answers1

0

Why you are creating the Javers bean on your own? javers-spring-boot-starter-sql creates all Javers' beans for you and it sets a proper SQL dialect. Try to switch to default Javers Spring config created by the Javers' starter.

Bartek Walacik
  • 3,386
  • 1
  • 9
  • 14
  • ^ answer edited ^ – Bartek Walacik Feb 20 '22 at 13:07
  • I recommend against rhetoric questions in answers. They risk being misunderstood as not an answer at all. You are trying to answer the question at the top of this page, aren't you? Otherwise please delete this post. – Yunnosch Feb 20 '22 at 14:45
  • @Yunnosch I don't understand why you give so much criticism about my a answer. If you don't like - you can still downwote it. Suggesting an author to delete his answer is very radical, especially if javers is not your area of expertise. – Bartek Walacik Feb 20 '22 at 19:01
  • I did not suggest to delete the answer. Just that I find it not very obviously an answer and if it is NOT meant to be one, to delete it. – Yunnosch Feb 20 '22 at 20:39