我有一个带有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
你很可能在这里需要双向关系。在Form
实体上添加适当的依赖关系:
@Entity
public class Form {
@Column
@UpdateTimestamp
Timestamp updateDateTime;
@OneToOne(mappedBy = "form")
private Application application;