我有以下 JPA 实体 - 规则和策略。我很喜欢,所以对规则的任何更新都会设置策略的 lastModified 日期。几个小时后,我发现我无法从 EntityListener 中调用 entityManager。
因此,我的问题是 ,当规则更新时,如何更新策略中的 lastModified 日期?
@Entity
@Table(name = "strategy")
public class Strategy {
@Id
@GeneratedValue
private Long id;
public void setId(Long id) {
this.id = id;
}
@Column(nullable = false)
private String name;
@Column
@Temporal(TemporalType.TIMESTAMP)
private Date modifiedDate;
@Table(name = "rule")
@EntityListeners({RuleListener.class})
public class Rule {
@Id
@GeneratedValue
private Long id;
@ManyToOne(/*optional = false, */fetch = FetchType.LAZY)
@JoinColumn(name="STRATEGY_ID"/*, nullable=false*/)
private Strategy strategy;
@Column(nullable = false)
private String name;