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: Help with the HQL query
PostPosted: Sun Aug 07, 2005 12:28 am 
Newbie

Joined: Wed Jul 27, 2005 3:44 pm
Posts: 12
Location: Los Angeles, CA
I have this SQL query, but I don't know how to do the same in HQL. How to specify multiple join conditions, e.g.
Code:
select * from A left outer join B on B.fk = A.id and B.effectiveDate = systemdate


i.e. The condition is not in WHERE, but in the JOIN.

Here's actual SQL query
Code:
select distinct adGroup.vendorIdString
from AdGroup as adGroup
join Campaign C on C.id = adGroup.campaignId
join VendorKeyword VK on VK.adGroupId = adGroup.id
left outer join KeywordStats S on S.vendorKeywordId = VK.id and (S.startDate = ? and S.endDate = ?)
where C.accountId = ?
     and adGroup.vendorIdString is not null
     and VK.isNegative = 0
group by adGroup.vendorIdString
having count (S.id) = 0


I have 1 Entity per Table mapping, so in Hibernate mapping file, entity names are same as table names. So I am not providing mapping files here.

If exact translation is not possible, I'd appreciate ideas on how to do the same thing efficiently in HQL. It should return those AdGroups that do not have KeywordStats for given dates.

Account has Campaigns, which has AdGroups which has VendorKeywords which has KeywordStats.

Thanks!!!

_________________
Maxim Senin
Custom Software Development for the Enterprise
http://www.supremistic.com/


Top
 Profile  
 
 Post subject: Re: Help with the HQL query
PostPosted: Tue Aug 09, 2005 7:03 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
msenin wrote:
Code:
select * from A left outer join B on B.fk = A.id and B.effectiveDate = systemdate


i.e. The condition is not in WHERE, but in the JOIN.


in hql you can have
Code:
select a from A as a left join a.b as b where (b.effectiveDate is null or b.effectiveDate = systemdate)

or you can use a subquery
Code:
from A as a  where a in (select a from A as a join a.b as b where b.effectiveDate <> systemdate)


Seb


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.