Quantcast

findAll method returning object array

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

findAll method returning object array

Erik Pragt-2
Hi all,

Just a small question: I'm trying to retreive some entities from my databases (Recipes in this case), and I'm using this query for that (simplified version):

def recipes = Recipe.findAll("from net.javaisp.cookbook.Recipe as r inner join r.ingredients as i ")

However, this doesn't return Recipe objects, but Object arrays of length 2, with Recipe and Ingredient classes. How can I prevent this from happening and only return Recipes?

I tried this:

def recipes = Recipe.findAll("select r from net.javaisp.cookbook.Recipe as r inner join r.ingredients as i");

But this is an incorrect query:

"errors.GrailsExceptionResolver org.codehaus.groovy.grails.orm.hibernate.exceptions.GrailsQueryException: Invalid query [select r from net.javaisp.cookbook.Recipe as r inner join r.ingredients as i] for domain class ......"

Suggestions??
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: findAll method returning object array

Miguel Ping
I'm not used to HQL, but I guess that the inner join forces the retrieval of both entities. 

I would do something like "from A where A.b is not null"

hTh, 
Miguel Ping

On Mon, Jan 12, 2009 at 8:22 AM, Erik Pragt <[hidden email]> wrote:

Hi all,

Just a small question: I'm trying to retreive some entities from my
databases (Recipes in this case), and I'm using this query for that
(simplified version):

def recipes = Recipe.findAll("from net.javaisp.cookbook.Recipe as r inner
join r.ingredients as i ")

However, this doesn't return Recipe objects, but Object arrays of length 2,
with Recipe and Ingredient classes. How can I prevent this from happening
and only return Recipes?

I tried this:

def recipes = Recipe.findAll("select r from net.javaisp.cookbook.Recipe as r
inner join r.ingredients as i");

But this is an incorrect query:

"errors.GrailsExceptionResolver
org.codehaus.groovy.grails.orm.hibernate.exceptions.GrailsQueryException:
Invalid query [select r from net.javaisp.cookbook.Recipe as r inner join
r.ingredients as i] for domain class ......"

Suggestions??
--
View this message in context: http://www.nabble.com/findAll-method-returning-object-array-tp21410300p21410300.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: findAll method returning object array

i_hernandez82
In reply to this post by Erik Pragt-2


Hi,

I have the same problem, I would like to use the select closure like hibernate allows in HQL ( see examples in : )

http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/queryhql.html#queryhql-aggregation

This HQL sentence is not possible currently in GORM, it would be very nice to have it :)
I am using grails 1.3.7

def theResult = Foo.findAll("select foo from Foo  foo, SubFoo subfoo where foo.subfooProperty= subfoo")

Best Regards
Loading...