Used to enhance or override the default bean persistence mechanism.
Note that if want to totally change the finding, you need to use a BeanQueryAdapter rather than using postLoad().
Note that getTransaction() on the PersistRequest returns the transaction used for the insert, update, delete or fetch. To explicitly use this same transaction you should use this transaction via methods on EbeanServer.
Object extaBeanToSave = ...; Transaction t = request.getTransaction(); EbeanServer server = request.getEbeanServer(); server.save(extraBeanToSave, t);
It is worth noting that BeanPersistListener is different in three main ways from BeanPersistController postXXX methods.
- BeanPersistListener only sees successfully committed events. BeanController pre and post methods occur before the commit or a rollback and will see events that are later rolled back
- BeanPersistListener runs in a background thread and will not effect the response time of the actual persist where as BeanController code will
- BeanPersistListener can be notified of events from other servers in a cluster.
A BeanPersistController is either found automatically via class path search or can be added programmatically via ServerConfiguration.addEntity().