javaspringspring-bootspring-data-jpajavers

Javers - findChanges do not record/pick nested VO


I have following code (java / jpa):

@NoArgsConstructor
@AllArgsConstructor
@ToString(onlyExplicitlyIncluded = true)
@Builder(toBuilder = true)
@Getter
@Setter
@Entity
public class Foo {
    @ToString.Include
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @ToString.Include
    @Valid
    @NotNull
    @AttributeOverride(
        name = "origin.elementType",
        column = @Column(name = "inclusion_origin_element_type", nullable = false)
    )
    @AttributeOverride(name = "origin.values", column = @Column(name = "inclusion_origin_value", length = 64))
    @AttributeOverride(name = "destination.elementType", column = @Column(name = "inclusion_destination_element_type"))
    @AttributeOverride(name = "destination.values", column = @Column(name = "inclusion_destination_value", length = 64))
    @AttributeOverride(name = "bothDirections", column = @Column(name = "inclusion_both_direction", nullable = false))
    @Embedded
    private CompositionDetails inclusions;

    @ToString.Include
    @Valid
    @Nullable
    @AttributeOverride(name = "origin.elementType", column = @Column(name = "exclusion_origin_element_type"))
    @AttributeOverride(name = "origin.values", column = @Column(name = "exclusion_origin_value", length = 64))
    @AttributeOverride(name = "destination.elementType", column = @Column(name = "exclusion_destination_element_type"))
    @AttributeOverride(name = "destination.values", column = @Column(name = "exclusion_destination_value", length = 64))
    @AttributeOverride(name = "bothDirections", column = @Column(name = "exclusion_both_direction"))
    @Embedded
    private CompositionDetails exclusions;

    //......
}

and

@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Setter
@Embeddable
public class CompositionDetails {

    @Valid
    @NotNull
    @Embedded
    private CompositionElement origin;

    @Valid
    @Nullable
    @Embedded
    private CompositionElement destination;

    @Builder.Default
    @Nullable
    private Boolean bothDirections = Boolean.FALSE;
}

and:

@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Getter
@Setter
@Embeddable
public class CompositionElement {

    @NotNull
    @Column(nullable = false, length = 16)
    @Enumerated(EnumType.STRING)
    private ElementType elementType;

    @Builder.Default
    @NotEmpty
    @ElementCollection(fetch = FetchType.EAGER)
    private List<String> values = new ArrayList<>();
}

If I persist the original Foo without exclusions and than update that entity with some exclusion value, following happens:

In logs, upon doing an update, I see following:

org.javers.core.Javers                   : Commit(id:11.00, snapshots:3, author:unknown, changes -), done in 5 ms (diff:4 ms, persist:1 ms)

which indicate there was no change 🤔 For sure the haschode differs between original entity state and update one.

I am confused - what am I doing wrong here?


for the record:


Solution

  • Not sure why... but using org.javers.core.metamodel.annotation.Value annotation on my CompositionDetails with an explicite @EqualsAndHashCode from lombok on CompositionDetails and CompositionElement did work.