Hibernate filter not applied to Model.findById

839 views
Skip to first unread message

Adam

unread,
Jun 10, 2011, 11:14:19 PM6/10/11
to play-framework
Hey all,

We're developing a multi-tenant application using using a single
database/ schema. To distinguish the data between each tenant we are
using hibernate filters that are applied @before each request in play
(then applying it manually for jobs etc.). There is a good, recent
tutorial that I've found <a href="http://www.lunatech-research.com/
archives/2011/03/04/play-framework-writing-multitenancy-application-
hibernate-filters">here</a>.

The filter appears to work find however it is not being applied to
findById in the models.

For example:
(the id is from another tenant and therefore should be filtered).
MyModel model1 = MyModel.findById(id);
MyModel model2 = MyModel.find("id = ?", id).first();

model1 returns the model associated with the id however model2 does
not (returns null). model2 is the correct behavior as this model is
from another tenant.

In play.db.jpa.JPQL.class, all of the find methods use createQuery
except findById - which itself uses EntityManager.find.

So it appears that the hibernate filter is only applied to createQuery
and not find. Is this the correct behavior or might I have some
configuration problem?

Thanks

Guillaume Bort

unread,
Jun 11, 2011, 8:04:34 AM6/11/11
to play-fr...@googlegroups.com
I think that hibernate filter can't work on findById since it is not
using a query.

> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

Adam

unread,
Jun 11, 2011, 8:36:02 AM6/11/11
to play-framework
Thanks for the prompt reply. I've just found a post on the hibernate
forums about it and it appears to be by design:
https://forum.hibernate.org/viewtopic.php?f=1&t=994201&view=previous

Good to know, Play is an awesome framework by the way. Remarkably fast
and great to develop on.

Adam

Peter Hilton, Lunatech

unread,
Jun 13, 2011, 4:47:35 AM6/13/11
to play-fr...@googlegroups.com
Exactly - findById ultimately does EntityManager.load, so you need to make your own findById method that does a query.
Reply all
Reply to author
Forward
0 new messages