I don't want to save in case when data the same in audit table new record, but anyway it saves changes in two tables and updates modifiedAt. Is there anything to avoid this behaviour?
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Data
@Audited
public class Book {
@Id
@GeneratedValue
private int id;
private String name;
private String data;
@NotAudited
private Instant receivedAt;
@LastModifiedDate
private Instant modifiedAt;
}
public void updateReceivedDate(Integer id, String data) {
Optional<Book> book = repository.findById(id);
if (book.isPresent() && data.equals(book.get().getData())) {
book.get().setReceivedAt(Instant.now());
repository.save(book.get());
}
}