我在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
答案 0 :(得分:0)
您很可能需要在此处建立双向关系。在Form
实体上添加适当的依赖项:
@Entity
public class Form {
@Column
@UpdateTimestamp
Timestamp updateDateTime;
@OneToOne(mappedBy = "form")
private Application application;