Search code examples
javajpajavers

Javers : "PROPERTY_NOT_FOUND: Property 'id' not found in class" happen randomly


I have an entity class "ContBox" with following fields map with JPA annotation and Javer annotation

@Id
private Long contBoxId;

@Column(name = "box_name")
@PropertyName("box_name")
@DiffInclude
private String boxName;

@Column(name = "box_desc")
@PropertyName("box_desc")
@DiffInclude
private String boxDesc;

When I try to run javers.compare, it hit the following error

org.javers.common.exception.JaversException: PROPERTY_NOT_FOUND: Property 'contBoxId' not found in class 'com.my.test.ContBox_$$_jvst966_b'. 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.EntityType.spawn(EntityType.java:49)
at org.javers.core.metamodel.type.EntityType.spawn(EntityType.java:36)
at org.javers.core.metamodel.type.TypeFactory.spawnFromPrototype(TypeFactory.java:116)
at org.javers.core.metamodel.type.TypeFactory.infer(TypeFactory.java:74)
at org.javers.core.metamodel.type.TypeMapperState.infer(TypeMapperState.java:157)
at org.javers.core.metamodel.type.TypeMapperState.lambda$getJaversType$0(TypeMapperState.java:89)
at org.javers.core.metamodel.type.TypeMapperState.computeIfAbsent(TypeMapperState.java:113)
at org.javers.core.metamodel.type.TypeMapperState.getJaversType(TypeMapperState.java:89)
at org.javers.core.metamodel.type.TypeMapper.getJaversType(TypeMapper.java:129)
at org.javers.core.diff.DiffFactory.buildGraph(DiffFactory.java:94)
at org.javers.core.diff.DiffFactory.compare(DiffFactory.java:54)
at org.javers.core.JaversCore.compare(JaversCore.java:173)

Note: It never cause error when i first create the record, it only happen randomly when i try to update the saved record and call javers.compare.

So I went to debug the javers class and here is my finding:

There error is cause by the "propertiesByName" doesn't have "contBoxId", "propertiesByName" only have those property with @DiffInclude annotation.

But this is an ID field and I don't need to compare it (I also tried to add @DiffInclude for the 'contBoxId', it hit ENTITY_INSTANCE_WITH_NULL_ID)

enter image description here enter image description here

This is only happen to this entity class while other entity class is working fine with javers.compare

I already try my best to find the cause but I really no idea how the error come from, because other entity class is using the same setting but they are all working fine !!

Is anyone have any idea on this ?


Solution

  • Finally I able to figure out the root cause, the answer is actually printed in the exception message :

    PROPERTY_NOT_FOUND: Property 'contBoxId' not found in class 'com.my.test.ContBox_$$_jvst966_b'.
    

    com.my.test.ContBox_$$_jvst966_b is a hibernate proxy object after perform a save, it's working fine after i unproxy it before passing to javers to compare changes.