Hibernate,更改父记录中更改的子记录的updatedTimestamp

问题描述 投票:0回答:1

我有一个带有Hibernate的spring启动应用程序。我有以下表格。

@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

java hibernate spring-boot foreign-keys hibernate-envers
1个回答
0
投票

你很可能在这里需要双向关系。在Form实体上添加适当的依赖关系:

@Entity
public class Form {

  @Column
  @UpdateTimestamp
  Timestamp updateDateTime;

  @OneToOne(mappedBy = "form")
  private Application application;
© www.soinside.com 2019 - 2024. All rights reserved.