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!
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!
Hi andrewyan...
I read ur problem but I have no idea for this..sorry..
Have a nice day..
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.
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)
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?
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.
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
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