-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL Query
PostPosted: Sat Feb 02, 2008 6:31 am 
Newbie

Joined: Sat Feb 02, 2008 6:27 am
Posts: 2
Could somone help me translate this SQL into HQL.Your help is highly appreciated

[code]
SELECT
name,
MAX(isinuse) AS isinuse
FROM
(
SELECT
c.DISPLAY_TEXT AS name,
MAX(DECODE(r.FK_COMPANY, s.FK_COMPANY, 1, 0)) isinuse
FROM
SOURCEREQUIREMENT sr,
SUBSCRIPTION s,
COMPANY c,
ROLE r
WHERE s.FK_SRCREQ = sr.PK_SRCREQ
AND s.FK_COMPANY = c.PK_COMPANY
AND sr.PK_SRCREQ = r.FK_SRCREQ
GROUP BY
c.DISPLAY_TEXT
UNION
SELECT
c.DISPLAY_TEXT AS name,
MAX(DECODE(p.FK_COMPANY, s.FK_COMPANY, 1, 0)) isinuse
FROM
SOURCEREQUIREMENT sr,
SUBSCRIPTION s,
COMPANY c,
PROCESS p
WHERE s.FK_SRCREQ = sr.PK_SRCREQ
AND s.FK_COMPANY = c.PK_COMPANY
AND sr.PK_SRCREQ = p.FK_SRCREQ
GROUP BY
c.DISPLAY_TEXT
)
GROUP BY name[/code]

Thnx in advance
Mani


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 7:00 am 
Regular
Regular

Joined: Mon Aug 20, 2007 6:47 am
Posts: 74
Location: UK
Nobody is going to be able to help you with this I'm afraid, as SQL can't be translated to HQL without contextual information like the database schema, hibernate mappings and java classes.

I suggest you search for some good HQL tutorials. If you get stuck with specific problems then post back.


Top
 Profile  
 
 Post subject: Tell us some more about your mapping and table relations
PostPosted: Sat Feb 02, 2008 10:29 am 
Newbie

Joined: Tue Jan 22, 2008 9:53 am
Posts: 18
Irons Uk is right.
We could translate this into a HQL query, but probably you would get the wrong answer.
You are selecting two fields from a subselction of an union of two selection in 4 different tables.
You have to map this correctly first. So tell us about your mapping schema, then we can try to help you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.