lundi 15 juin 2020

Javers - problem with DiffIgnore on Id property when running all test suits


I have Java SpringBoot application with Hibernate, JPA and Groovy tests with H2 db. I use javers to build history of etities change for users. When I wrote test case with deleting entity and checking is the change has been written to the database everything went ok - many times. Same with taste suit. But when I lunched all test suits for the second time the test returns:

"PROPERTY_NOT_FOUND: Property 'id' not found in class '(...)WholesalerResponsiblePerson$HibernateProxy$YlMKvBH5'. If the name is correct - check annotations. Properties with @DiffIgnore or @Transient are not visible for JaVers."

When I restarts my IDE, and run all test suits for the first time, the test ends ok, but the second time ends with this exception.

@EqualsAndHashCode(callSuper = true) 
@Entity 
@Table 
@Data 
@AllArgsConstructor 
@NoArgsConstructor

public class WholesalerResponsiblePerson extends BaseEntity {

@Id
@GeneratedValue(strategy = IDENTITY)
@DiffIgnore
private Long id;

private boolean active;

@DateTimeFormat(iso = DATE)
private LocalDate termPerformingFunctionsFrom;
{*other properties*}
}

Why only with all test lunched Javers tries to find 'id' and can't find it when it is second run of all tests - some cashed memory that do not clear with ordinary dbCleaner? Of course when I remove the @DiffIgnore everything goes as it should be, but it's not the case. I like to leave the annotation because I don't need to compare Id's.

Dependency:
compile group: 'org.javers', name: 'javers-spring-boot-starter-sql', version: '5.8.6'
compile group: 'org.javers', name: 'javers-core', version: '5.8.6'

Stack trace:

org.javers.common.exception.JaversException: PROPERTY_NOT_FOUND: Property 'id' not found in class '{...}WholesalerResponsiblePerson$HibernateProxy$YlMKvBH5'. If the name is correct - check annotations. Properties with @DiffIgnore or @Transient are not visible for JaVers. at org.javers.core.metamodel.type.ManagedClass.getProperty(ManagedClass.java:83) at org.javers.core.metamodel.type.ManagedClass.lambda$getProperties$1(ManagedClass.java:93) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) at org.javers.core.metamodel.type.ManagedClass.getProperties(ManagedClass.java:93) at org.javers.core.metamodel.type.EntityType.spawn(EntityType.java:60) at org.javers.core.metamodel.type.EntityType.spawn(EntityType.java:44) at org.javers.core.metamodel.type.TypeFactory.spawnFromPrototype(TypeFactory.java:135) at org.javers.core.metamodel.type.TypeFactory.infer(TypeFactory.java:93) at org.javers.core.metamodel.type.TypeMapper.lambda$getJaversType$0(TypeMapper.java:122) at org.javers.core.metamodel.type.TypeMapperEngine.computeIfAbsent(TypeMapperEngine.java:91) at org.javers.core.metamodel.type.TypeMapper.getJaversType(TypeMapper.java:122) at org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:96) at org.javers.core.diff.DiffFactory.compare(DiffFactory.java:54) at org.javers.core.JaversCore.compare(JaversCore.java:171) at org.javers.spring.jpa.JaversTransactionalDecorator.compare(JaversTransactionalDecorator.java:111) at org.javers.spring.jpa.JaversTransactionalDecorator$$FastClassBySpringCGLIB$$acb40bd0.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:685) at org.javers.spring.jpa.JaversTransactionalDecorator$$EnhancerBySpringCGLIB$$a927a213.compare()


PS. Other test with javers are ok, just this with delete.

Aucun commentaire:

Enregistrer un commentaire