Javers Entity referenced by another Entity : displaying changes on ID not properties

1 day ago 3
ARTICLE AD BOX

Javers 7.10.0

I have a Javers bean defined as shown below. My domain model classes extend an abstract class called Entity.

return JaversBuilder.javers() .registerEntity( EntityDefinitionBuilder.entityDefinition(Entity.class) .withIdPropertyName("id") .build()) .registerJaversRepository(mongoRepository) .build();

Let’s say I have a class Foo that references Product. Both Foo and Product extend Entity.

public class Foo extends Entity { private String someProperty; private Product product; // ... } public class Product extends Entity { private String code; // ... }

A javers.commit call is made on the Foo entity with a populated Product object containing a specific code.

Whenever I update the Foo entity with a different product.code, I would like to see detailed changes for the Product properties, indicating that product.code changed from XXX to YYY.

However, when I query changes on the Foo entity using javers.findChanges(queryBuilder.withChildValueObjects().build()), I only see that product.id changed from 1 to 3.

... "changeType" : "PROPERTY_VALUE_CHANGED", "propertyName" : "product", "left" : { "typeName" : " ... model.common.Product", "cdoId" : 1 }, "right" : { "typeName" : "... .model.common.Product", "cdoId" : 3 } ...

It works as expected if I declare Foo as an Entity and Product as a ValueObject. However, I also need to audit Product itself and be able to query it independently.

I feel like I might be missing something. Do you have any suggestions?

Read Entire Article