4 Replies Latest reply on Mar 25, 2006 10:34 AM by epbernard

    Runtime change of @Where clause

    lcoetzee

      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

        • 1. Re: Runtime change of @Where clause
          asack

           

          "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

            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

              Will you pay me a beer if I give you the feature you want?

              • 4. Re: Runtime change of @Where clause
                epbernard

                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