How to register ebean Controllers (preInsert, postLoad, etc) ?

626 views
Skip to first unread message

Gyorn

unread,
Apr 7, 2012, 12:48:57 PM4/7/12
to play-fr...@googlegroups.com
Hi,

I'm having a hard time trying to execute some Post* and Pre* action to my entities. What is the proper way to do this with ebean ?

"A no operation implementation of BeanPersistController. Objects extending this need to only override the methods they want to."
"A BeanPersistAdapter is either found automatically via class path search or can be added programmatically via ServerConfig.add(BeanPersistController) orServerConfig.setPersistControllers(java.util.List)."

But I can't make it work with Play. The controller won't get registered by himself, and I don't know how to retrieve the ServerConfig instance to add them manualy. For information i have a Document and DocumentController in the same package (models)



Kevin Bosman

unread,
Apr 7, 2012, 1:25:20 PM4/7/12
to play-fr...@googlegroups.com
Create a BeanPersistAdapter derivative, and add the fully qualified
class name to the ebean.default key in your application.conf file.
By default it reads models.*

So eg. you would need to change it to:
ebean.default="models.*,models.adapters.OrderPersistAdapter"

Gyorn

unread,
Apr 7, 2012, 5:32:21 PM4/7/12
to play-fr...@googlegroups.com
Thanks ! it works :)

But it's a bit weird that we have to add the fully qualified class name in the app.conf...  models.adapters.* sould be enough ..

Kevin Bosman

unread,
Apr 7, 2012, 5:38:59 PM4/7/12
to play-fr...@googlegroups.com
> But it's a bit weird that we have to add the fully qualified class name in
> the app.conf...  models.adapters.* sould be enough ..

Play checks for those classes matching the wildcard that have the
annotations @Entity or @Embeddable. If you think about it, that
actually makes a lot of sense, because you can't be guaranteed that
everything in your models package is going to be an ebean class.
PersistAdapter and some others don't have annotations, so it's a small
price to pay imho.

Gyorn

unread,
Apr 8, 2012, 2:01:25 PM4/8/12
to play-fr...@googlegroups.com
Yeah you're probably right. It's just that I didn't expected it because of the ebean API doc, where they say :  "A BeanPersistAdapter is either found automatically via class path search or can be added programmatically"

To avoid putting every adapter in the application.conf, wich could lead to many prolems, i've found this adapter :

Kevin Bosman

unread,
Apr 9, 2012, 8:18:26 AM4/9/12
to play-fr...@googlegroups.com
> It's just that I didn't expected it because of
> the ebean API doc, where they say :  "A BeanPersistAdapter is either found
> automatically via class path search or can be added programmatically"

Yes, that threw me too when I first went through that.

> To avoid putting every adapter in the application.conf, wich could lead to
> many prolems, i've found this adapter :
> http://dominikdorn.com/2012/01/jpa-entity-listener-annotations-avaje-ebean/

That's pretty cool. Thanks for the link!

julien Tournay

unread,
Apr 9, 2012, 1:13:29 PM4/9/12
to play-fr...@googlegroups.com
Hi,

Play could also look for instances of BeanPersistAdapter.
Maybe you should suggest that in lighthouse.

jto.

Joscha Feth

unread,
May 9, 2012, 5:37:22 PM5/9/12
to play-fr...@googlegroups.com
> To avoid putting every adapter in the application.conf, wich could lead to

> many prolems, i've found this adapter :
> http://dominikdorn.com/2012/01/jpa-entity-listener-annotations-avaje-ebean/

That's pretty cool. Thanks for the link!

The link seems to be down, but I could find the gist named in that article - for future reference: https://gist.github.com/1547244
 
Reply all
Reply to author
Forward
0 new messages