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: Can someone help me get started converting this query?
PostPosted: Wed Apr 16, 2008 11:52 am 
Newbie

Joined: Tue Nov 06, 2007 1:37 pm
Posts: 7
Here is the query:

DECLARE @zip VARCHAR(20)
SET @zip = '90210'

--Get Partial Zip Matches
SELECT DISTINCT p.* FROM dbo.[Plan] p
INNER JOIN dbo.[PlanCounty] pc ON p.PlanID=pc.PlanID
INNER JOIN dbo.[PlanCountyPartialZip] ppz ON pc.PlanCountyID=ppz.PlanCountyID
INNER JOIN dbo.[Zip] z ON ppz.ZipID=z.ZipID
WHERE z.Zipcode=@zip
UNION ALL
--Get Non-Partial Zip Matches
SELECT DISTINCT p.* FROM dbo.[Plan] p
INNER JOIN dbo.[PlanCounty] pc ON p.PlanID=pc.PlanID
INNER JOIN dbo.[County] c ON pc.CountyID=c.CountyID
INNER JOIN dbo.[CountyZip] cz ON c.CountyID=cz.CountyID
INNER JOIN dbo.[Zip] z ON cz.ZipID=z.ZipID
WHERE (pc.PlanCountyID NOT IN (SELECT DISTINCT PlanCountyID FROM PlanCountyPartialZip))
AND (z.Zipcode=@zip)

I would like to convert this using HQL or Criteria but I don't know where to get started.

Can anyone help me with an approach that would work best?

Thanks,

jensenkd


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 17, 2008 10:04 am 
Newbie

Joined: Fri Mar 28, 2008 2:37 pm
Posts: 4
Location: Toronto
jensenkd,
basiclly HQL do not allow Union, all other conditions could be set in the HBM files
So assuming in here that you have all your tables properly linked to objects throw hibernate, here is what you should do

Code:
query = session.CreateQuery("From PartialZip where Zipcode=:Zipcode");
query.SetString("Zipcode", "sometext");
List x = session.List();

session.CreateQuery("From NonPartialZip where Zipcode=:Zipcode");
query.SetString("Zipcode", "sometext");
List y = session.List();

x.addAll(y);


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.