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:
javers.findChanges(QueryBuilder.byInstanceId(id, clazz).withChildValueObjects(true).build())
- do not pick the update, only one 'change' is returned - the original 'create'javers.findSnapshots(QueryBuilder.byInstanceId(id, clazz).withChildValueObjects(true).build())
- shows two versions, and in property change I can see 'exclusion' was updatedjavers.findShadows(QueryBuilder.byInstanceId(id, clazz).withChildValueObjects(true).build())
- shows two versions, with expected 'base' value (without exclusion) and new version with exclusionIn 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:
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.