5 Replies Latest reply on Oct 4, 2010 3:27 PM by lrpieri

    EJBQL and Logged User

    lrpieri

      Hi,


      I'd like to write a EJBQL where I can filter considering the logged user and its roles.
      For example the logged user is associated to a company, and, if hasRole('admin') he can se all companies, otherwise, he can se just the company he is associated. I have the logged user in session and he has his associated company.


      At the end, I'll want to lead more complex then it, but for now it would enough.


      Any idea?


      Thanks for all

        • 1. Re: EJBQL and Logged User
          lrpieri

          Can anybody help me?


          Tks (-:

          • 2. Re: EJBQL and Logged User
            lvdberg

            Hi,


            This is really a question for the Hibernate forum!


            Leo

            • 3. Re: EJBQL and Logged User
              lrpieri

              I'm sorry Leo but I can't agree to you. My problem is happening in a extension of EntityQuery becouse of it's limitations, or mine. :-)
              In one case the query will just list (and if need filter) the content of a table, in other case, the same extension of EntityQuery will need a query where will exists joins.


              The question is: can I change the EJBQL and RESTRICTIONS dynamically?
              If yes, what is the elegant way to do this?


              Tks


              Regards


              Rogério De Pieri

              • 4. Re: EJBQL and Logged User
                lvdberg

                Hi,


                The nice thing of Seam and JPA is that Seam intercepts the query string and looks for EL and replaces it on the fly. so basically YES you can change it dynamically. My personal preference to do this kind of things OUTSIDE the bean-code because you're mixing things which makes it difficult to maintain.


                Whenevr I need a dynamic query I use the possibilities of components.xml to define it.


                Leo

                • 5. Re: EJBQL and Logged User
                  lrpieri

                  Hi Leo,


                  I've solved my problem overriding the method getEJBQL and it seems the solution is ok. I change the return no method according the user roles.


                  Thanks for your help