Is it possible to use @PrePersist and @PreUpdate with eBean and Play! 2.0?

I want to know if @PrePersist and @PreUpdate can be used with Ebean and Play! 2.0. If so, how is this feature activated. I saw that there was a request by adding this function a month ago, but I can not do this work in Play 2.0.

thanks

+7
source share
4 answers

If your goal is simply to set the createdAt or updatedAt fields and you are using EBean, try @CreatedTimestamp and @UpdatedTimestamp . See here . I would rather use the Biesior approach, but it doesn't seem to work on Cascades - the methods have never been called.

 @Column(name="created_at") @CreatedTimestamp private Date createdAt; @Column(name="updated_at") @UpdatedTimestamp private Date updatedAt; 
+10
source

Not a direct answer, but you can mimic these functions by overriding the methods of the Model class in your model, sample:

 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); } } 
+4
source

It seems that you need to implement a BeanPersistController that offers pre-processing and post-processing options.

To configure it in Play, modify the application.conf file as such :

ebean.default="models.*,models.adapters.YourPersistController" .

+3
source

I'm very late for this, but you can use this: https://gist.github.com/1547244 . You will need to register this class in your application.conf application as follows:

 ebean.default="models.*, models.sgcore.SGBeanPersistController" 
+1
source

All Articles