Enhancement 235 : @PrePersist, @PostPersist, @PostLoad,...
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
github
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
05/03/2010
Updated 
05/03/2010
Type 
Enhancement
 
Attachments 
No attachments

lifesycle management via annotations would be handy

 
Rob 05 Mar 22:26
Yup .. check BeanPersistControll and BeanPersistListener though ...

Quite right. At the moment you have to use the Ebean specific BeanPersistController.

However, the BeanPersistController does do more ... takes into account partial objects (loaded properties), gives you access to the transaction and server that is processing the persist request etc, allows you to override the insert/update/delete behaviour.

Also note that often @PostPersist is NOT what you want as that fires even when a transaction rolls back - in this case you'd want to use a BeanPersistListener instead.

So yes, we need to add support for the annotations... but be careful because sometimes you might need to use a BeanPersistController or BeanPersistListener instead.

Cheers, Rob.

Rob 15 Mar 23:37
Hmmm... partial objects

For people using partial objects then the @Pre* @Post* annotations in JPA are not going to be very good.

Specifically, most of the time you are going to also need to know which properties where loaded or updated etc.

It is not clear to me people understand this (and just use the @Pre* @Post* annotations and end up having problems).

Lyubo 31 Mar 13:55
PostLoad usage

Well, I have a particular use case where I need to do some action when object loads - de-serializing some (@Transient) fields stored in a single database field. This can be done with BeanPersistListener indeed (and this is the way we currently do it) but @PostLoad on a class method would encapsulate class code better.

Dominik Dorn 20 Feb 11:46
Solution ;)

Rob 14 Mar 11:21
Good stuff..

Hi,

Good work there.

What I have been thinking about is using a thread local so that the BeanPersistRequest and its associated information is available if/when people need it.

I'd also need to do something similar for PostLoad.

// for pre- post- insert, update, delete

BeanPersistContext.getEbeanServer();
BeanPersistContext.getTransaction();

// for pre- post- update

BeanPersistContext.getUpdatedProperties();
BeanPersistContext.getLoadedProperties();
BeanPersistContext.getOldValues();


// for post load

PostLoadContext.getLoadedProperties();

That way people can use the annotations and not fall into a hole.

woResponse

Upload a file