【发布时间】:2014-09-15 20:55:51
【问题描述】:
我有一个带有 updatedUser 字段的实体,它跟踪更新行值的用户。
创建实体时,此字段为空,但应在对实体进行更改并使用merge 时设置它。
有没有什么方法,通过java,只在实体更新时填充这个值? IE:如果它是从数据库创建或检索的,则不应更改。
@Entity
@Table(name="employees", uniqueConstraints= {
@UniqueConstraint(columnNames="idEmployees"),
@UniqueConstraint(columnNames="idCardNumber"),
@UniqueConstraint(columnNames="niNumber")
})
public class Employee {
@Id
@GeneratedValue
@Column(unique=true, nullable=false, updatable=false)
private int idEmployees;
//other class variables
@ManyToOne(cascade=CascadeType.PERSIST, fetch=FetchType.LAZY)
@JoinColumn(name="updatedEmployeeId")
private Employee updatedEmployee;
//constructors, getters and setters
}
【问题讨论】: