-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HQL: is it possible to access elements of elements?
PostPosted: Thu Jan 26, 2006 7:56 am 
Beginner
Beginner

Joined: Sun Jan 22, 2006 6:56 am
Posts: 29
I'm trying to use the elements() function in HQL to get an instance that has exactly the same collection elements from a DB.

This works fine:
Code:
SELECT person FROM Person person
WHERE
    EXISTS (
         SELECT kitten FROM Kitten kitten
         WHERE
              kitten.name in ('Moses', 'Shrek')
              AND
              kitten = all elements(person.cats.kittens)
     )


But if there's another collection in the path it doesn't:

Code:
SELECT person FROM Person person
WHERE
    EXISTS (
         SELECT yarnBall FROM YarnBall yarnBall
         WHERE
              yarnBall.color in ('Green', 'Red')
              AND
              yarnBall = all elements(person.cats.kittens.yarnBalls)
     )


I thought maybe i need to do something like:
Code:
yarnBall = all elements(elements(person.cats.kittens).yarnBalls)


But that doesn't work (get an exception about an illegal '.')
Is there any way to do this?

Hibernate version: 3.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 8:31 am 
Beginner
Beginner

Joined: Sun Jan 22, 2006 6:56 am
Posts: 29
OK, I think i've solved my problem - just need to use explicit joins:

Code:
SELECT person
FROM
     Person person
     JOIN person.cats cat
     JOIN cat.kittens kitten

WHERE
     EXISTS (
         SELECT yarnBall FROM YarnBall yarnBall
         WHERE
              yarnBall.color IN ('Green', 'Red')
              AND
              yarnBall = all elements (kitten.yarnBalls)
     )


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.