休眠,更改父记录更改后的子记录的updatedTimestamp

时间:2019-04-03 09:08:32

标签: java hibernate spring-boot foreign-keys hibernate-envers

我在Hibernate中有一个spring boot应用程序。我有下表。

@Entity
public class Application1 {

   @JoinColumn(name = "form_id")
   @OneToOne
   Form form;

  @Column
  @UpdateTimestamp
  Timestamp updateDateTime;

   <<other fields  here>> 
}

@Entity
public class Application2 {

   @JoinColumn(name = "form_id")
   @OneToOne
   Form form;

  @Column
  @UpdateTimestamp
  Timestamp updateDateTime;

   <<other fields  here>> 
}

@Entity
public class Form {

  @Column
  @UpdateTimestamp
  Timestamp updateDateTime;

   <<other fields  here>> 
}

updateDateTime 随对应表的每次更新而更新。但是我想要的是只要 Form 表发生变化,就更新 Application1 Applicatin2 表的 updateDateTime

1 个答案:

答案 0 :(得分:0)

您很可能需要在此处建立双向关系。在Form实体上添加适当的依赖项:

@Entity
public class Form {

  @Column
  @UpdateTimestamp
  Timestamp updateDateTime;

  @OneToOne(mappedBy = "form")
  private Application application;