This content has been marked as final.
Show 4 replies
-
1. Re: Runtime change of @Where clause
asack Mar 22, 2006 1:05 PM (in response to lcoetzee)"lcoetzee" wrote:
Hi,
Is it possible to change the @Where clause at runtime, thus implementing some kind of polymorphic query on my collection ?
As an example I have the following:@OneToMany(mappedBy = "service") @MapKey(name="id") @Where(clause="topic_type='CMS'") public Map<Integer,Topic> getTopics() { return topics; }
This retrieves all the topics of type 'CMS'. At runtime I would like to set the topic_type to 'DF' for instance, which will return only the topics with topic_type 'DF'. Any suggestions would be welcome.
Regards
Louis
Not exactly sure, but couldn't you define an @Interceptor class that defines a pointcut around getTopics() then use Reflection to grab the @Where annotation and change the topci_type to DF? Not sure if I'm missing something since I"m fairly new to AOP and design but it seems possible at first glance. -
2. Re: Runtime change of @Where clause
lcoetzee Mar 23, 2006 4:36 AM (in response to lcoetzee)I agree that such a sollution might be possible. However, it would be fantastic to have somekind of standard API to change that setting. Am I missing something somewhere ?
Thanks
L -
3. Re: Runtime change of @Where clause
epbernard Mar 25, 2006 10:33 AM (in response to lcoetzee)Will you pay me a beer if I give you the feature you want?
-
4. Re: Runtime change of @Where clause
epbernard Mar 25, 2006 10:34 AM (in response to lcoetzee)ah, I'm going to give it to you anyway ;-)
So use an Hibernate Filter, this is some kind of additional where clause that you can enable or disable at runtime. you also can use more than one filter at a given time