以下の JPA エンティティがあり、@PrePersist と @PreUpdate を使用して、Spring コンテキストから現在のユーザーで lastUpdatedBy 文字列の設定を容易にしたいのですが、エンティティからその情報にアクセスする方法がわかりませんレベルのコンテキスト。何か案は?
public abstract class BaseEntity {
private Date createdDate;
private String lastUpdatedBy;
@Column(name = "LAST_UPDATED_BY")
public String getLastUpdatedBy() {
return lastUpdatedBy;
}
public void setLastUpdatedBy(String lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="CREATED_DATE")
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date created) {
if (created != null) {
this.createdDate = created;
}
}
@PrePersist
protected void onCreate() {
createdDate = new Date();
//lastUpdatedBy = //need to access Spring user here
}
@PreUpdate
public void onUpdate() {
updatedDate = new Date();
//lastUpdatedBy = //need to access Spring user here
}
}