Playframework 是否可以将@PrePersist和@PreUpdate与eBean一起使用并播放!2.0?
我想知道是否可以将Playframework 是否可以将@PrePersist和@PreUpdate与eBean一起使用并播放!2.0?,playframework,playframework-2.0,ebean,Playframework,Playframework 2.0,Ebean,我想知道是否可以将@PrePersist和@PreUpdate与Ebean一起使用并播放!2.0. 如果是,该功能是如何激活的。我在一个月前看到有人添加了这个功能,但我无法在Play2.0上实现这一点 多谢似乎应该实现,它提供了预处理和后处理选项 要在游戏中配置它,请修改application.conf文件: ebean.default=“models.*,models.adapters.YourPersistController”不是一个直接的答案,但您可以通过覆盖模型中Model类的方法来模
@PrePersist
和@PreUpdate
与Ebean
一起使用并播放!2.0. 如果是,该功能是如何激活的。我在一个月前看到有人添加了这个功能,但我无法在Play2.0上实现这一点
多谢似乎应该实现,它提供了预处理和后处理选项 要在游戏中配置它,请修改
application.conf
文件:
ebean.default=“models.*,models.adapters.YourPersistController”
不是一个直接的答案,但您可以通过覆盖模型中Model
类的方法来模拟这些功能,示例:
public class Post extends Model {
// ....
@Override
public void save() {
this.createDate = new Date();
this.modifyDate = new Date();
super.save();
}
@Override
public void update(Object o) {
this.modifyDate = new Date();
super.update(o);
}
}
我真的迟到了,但你可以用这个:。您需要在application.conf中注册此类,如下所示:
ebean.default="models.*, models.sgcore.SGBeanPersistController"
如果您的目标只是设置createdAt或updatedAt字段,并且您正在使用EBean,请尝试
@CreatedTimestamp
和@UpdateTimeStamp
。看见我更愿意使用Biesior的方法,但它似乎在级联上失败了——这些方法从未被调用过
@Column(name="created_at")
@CreatedTimestamp
private Date createdAt;
@Column(name="updated_at")
@UpdatedTimestamp
private Date updatedAt;
据我所知,BeanPersistListener应该可以使用,尽管我不知道如何在Play2中配置它。