Grails HQL Query -- Cannot Join Multiple Collections "hasMany" relationships

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Grails HQL Query -- Cannot Join Multiple Collections "hasMany" relationships

jried31
-------------------DOMAIN CLASSES--------------------
class Venture{
static hasMany = [executives:Role,advisors:Role, team:Role]}

class Role{
Person owner
}
--------------------Goal Trying to Obtain-----------------------
Return all Venture instances where the Person "userId" has a designated Role

---------------------The Query--------------------------
select venture from Venture venture
inner join venture.executives as ex
inner join venture.advisors as av
inner join venture.team as tm
where :userId in elements(ex.owner) or :personInstance in elements(av.owner) or :personInstance in elements(tm.owner)

-----------------------HQL Exception I get-------------------------
Message: unexpected token: exists near line 6, column 23 [
select venture from TEC.Venture venture
inner join venture.executives as ex
inner join venture.advisors as av
inner join venture.team as tm
where :userId exists elements(ex.owner) or :userId exists elements(av.owner) or :userId exists elements(tm.owner)
]
Reply | Threaded
Open this post in threaded view
|

Re: Grails HQL Query -- Cannot Join Multiple Collections "hasMany" relationships

jried31
I solved this problem by performing separate queries than joining the results.....However, if there's any feedback you can offer regarding how to join multiple associations and filter based upon the ids of a child attribute within the association it will be greatly helpful!