-->
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.  [ 1 post ] 
Author Message
 Post subject: Basic query question
PostPosted: Thu Mar 03, 2005 8:04 am 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Hi

I have a parent-child relationship. Everything works fine. but I'm stuck with a query. I can do it SQL but I have problem how to translate it to HQL.

Both the PARENT and the CHILD object has a field STATUS.

I need to retrieve all the PARENT objects from the DB

where

- either the PARENTs status is X
- or any of it's childs status is X


mitgliedschaftschutzbrief = parent
kinderleistungsart = child

this is the hibernate query I'm using ->

select distinct mitgliedschaftschutzbrief
from MitgliedschaftSchutzbrief as mitgliedschaftschutzbrief, Kinderleistungsart as kinderleistungsart

where (mitgliedschaftschutzbrief.verarbeitungsstatus = :status
or (kinderleistungsart.verarbeitungsstatus = :status AND kinderleistungsart in elements(mitgliedschaftschutzbrief.kinder)))

this works if there is any child for a parent. but gives problems if no child belongs to a parent.

what is the best way.

CAN I have something like UNION in sql where I could just have 2 different queries and use their UNION.

this is the SQL (oracle) which gives me the perfect result:

select mitgliedsc0_.*
from
mapl.MITGLIEDSCHAFT_SCHUTZBRIEF mitgliedsc0_
where
(
( mitgliedsc0_.verarbeitungsstatus='U' )
or exists ( select 1 from mapl.KINDERLEISTUNGSART kinderleis_
where kinderleis_.mg_nr = mitgliedsc0_.mg_nr
and kinderleis_.verarbeitungsstatus='U'
)
)

order by mitgliedsc0_.satzart desc

Thanks for any help or hint


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

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.