Search code examples
javahibernatespring-bootjavers

How to get changes of embeddable?


I'm having an Entity with an embedded Entity in spring boot.

Now when my embedded entity has changes and I query my Entity for changes the changes are not in the change list.

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TaskEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Embedded
    private LockSettingsEmbeddable lockSettings;
}

@Embeddable
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LockSettingsEmbeddable {
    private boolean locked;
    @Enumerated(EnumType.STRING)
    private TaskLock lockSetting;
}

List<Change> changes = javers.findChanges(QueryBuilder.byInstanceId(taskId, TaskEntity.class).build());
        List<Change> modifiableList = new ArrayList<>(changes);
        modifiableList.sort((o1, o2) -> -1 * o1.getCommitMetadata().get().getCommitDate().compareTo(o2.getCommitMetadata().get().getCommitDate()));

        return javers.getJsonConverter().toJson(modifiableList);

Solution

  • Just enable the withChildValueObject filter, see https://javers.org/documentation/jql-examples/#child-value-objects-filter