Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Query by example?

  1. #1
    Join Date
    Feb 2012
    Posts
    6

    Default 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. #2

    Default

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

  3. #3
    Join Date
    Feb 2012
    Posts
    6

    Default

    Quote 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?

  4. #4
    Join Date
    May 2006
    Location
    Madrid
    Posts
    382

    Default

    Try to create finders

  5. #5
    Join Date
    Feb 2012
    Posts
    6

    Default

    Quote 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 at 09:13 AM.

  6. #6
    Join Date
    May 2006
    Location
    Madrid
    Posts
    382

    Default

    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)

  7. #7
    Join Date
    Feb 2012
    Posts
    6

    Default

    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?

  8. #8
    Join Date
    May 2006
    Location
    Madrid
    Posts
    382

    Default

    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.

  9. #9
    Join Date
    Feb 2012
    Posts
    6

    Default

    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

  10. #10
    Join Date
    Jan 2012
    Posts
    1

    Default

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •