I'm using Spring Data JPA for Auditing. There's a unidirectional relationship between classes Article and File. The Article class looks like this:
@Getter
@Entity
@SuperBuilder(toBuilder = true)
@Table(name = "article")
public class Article extends AuditEntity {
...
@Builder.Default
@OneToMany(fetch = FetchType.LAZY, orphanRemoval = true)
@JoinTable(name = "article_additional_file",
joinColumns = @JoinColumn(name = "article_id"),
inverseJoinColumns = @JoinColumn(name = "additional_file_id"))
private List<File> additionalFiles = new ArrayList<>();
...
}
The problem is, when changes occur in the file list (owned files get deleted or added), the modifiedDate field (which is in AuditEntity class and it's annotated with @LastModifiedDate annotation) is not updated (it works with all other fields). And I cannot make it a bidirectional relationship since other classes own the File class as well. So my question is, how to trigger the update of field modifiedDate when changes occur in the file list?
EDIT I'd prefer not to use Enver, if that's possible. I need to use as little additional libraries as possible