Announcement Announcement Module
Collapse
No announcement yet.
Query by example? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query by example?

    Hi all,

    As a newbie 2 weeks new to Roo, I'm trying to do query by example on my Roo built entities. I can probably write my own DAO, but according to the Roo docs it's clearly discouraged...

    Any suggestions?

    Thanks!

  • #2
    Hi andrewyan...
    I read ur problem but I have no idea for this..sorry..
    Have a nice day..

    Comment


    • #3
      Originally posted by shalini23 View Post
      Hi andrewyan...
      I read ur problem but I have no idea for this..sorry..
      Have a nice day..
      Thanks shalini23, at least I know the answer now, haha. Can this be done by creating my own addon?

      Comment


      • #4
        Try to create finders

        Comment


        • #5
          Originally posted by jbbarquero View Post
          Try to create finders
          Thanks jbbarquero,

          Yeah, I checked that. From my understanding, finders method need to specify the properties to be queried by (please correct me if I'm wrong).

          For my case, I don't know what the request party will query by ahead of time. The request party simply pass me an object and I've to query by the properties in the object.

          Is it possible to create a FinderAll method?
          Last edited by andrewyan; Feb 17th, 2012, 09:13 AM.

          Comment


          • #6
            You could create your own finder method in the @Entity (the Java class)

            Just use one existing finder as base and fill your method with whatever "if" sentences you need.

            Just a warning: you have to use JPA-QL, not plain SQL (maybe the best approach is ro create a lot of finders and to copy code from them, the most code you copy, the better your method will be)

            Comment


            • #7
              Thanks for the ideas!

              I'm just a little worried that I'll have a lot of if's in my method and I've to create a lot of finders to support that. If I've a class with 10 fields, I'll need 10! mutations for finders and many if's in my methods..... Or I'm on completely wrong direction?

              Comment


              • #8
                You're welcome.

                Maybe I didn't express correctly. What I did in a similar situation is a filter method with an object which attributes are objects that are either null or a value to filter (with additional info if you want to compare with less, greater or similar)

                Add to a StringBuilder the predicate that you're obtaining and finally execute the query (if you begin with "where 1=1" you'll save a first "if")

                There is a big con, you'll need to create this filter info object, in the tests and in the controller.

                And yes, you'll write a lot of if-else sentences.

                I hope it helps you.

                Comment


                • #9
                  Thanks again jbbarquero! I'll certainly try out your solution.

                  I just hope that we can do something like an Example query in Hibernate:
                  http://docs.jboss.org/hibernate/orm/...teria-examples

                  Comment


                  • #10
                    Springfuse provided QBE with Spring Data JPA:
                    http://www.springfuse.com/2012/01/31...-data-jpa.html

                    and they also provided sample source code here:
                    https://github.com/jaxio/generated-projects

                    Comment


                    • #11
                      You are the best!! Will check them out!

                      Comment

                      Working...
                      X