How to check OneToMany relationship changes on a native object using Spring JPA data?

I have successfully configured JPA auditing in essence. It works fine provided that there are changes in the data of the object itself. However, the entity contains the @OneToMany collection, and I would like the owning entity field to @LastModifiedByalso be updated when only the child rows are changed. I do not want to add audit fields to each line, if possible.

Defining a relationship in the parent:

@Entity
@EntityListeners(AuditingEntityListener.class)
public class DataHead {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

    @CreatedBy
    private String creatorUser;

    @CreatedDate
    private Date createdDate;

    @LastModifiedBy
    private String modifierUser;

    @LastModifiedDate
    private Date modifiedDate;

    @OneToMany(mappedBy="dataHead", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval=true)
    @Fetch(FetchMode.SUBSELECT)
    @Valid
    private List<DataRow> rows = new AutoPopulatingList<DataRow>(DataRow.class);
    ...
}

Tried to add @EntityListenersto the child, did not help.

I am using spring -data-jpa 1.9.4 with Hibernate 4.3.11 as an implementation.

+4
source share

All Articles