-->
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: Hibernate generates unwanted cross join
PostPosted: Fri Jul 16, 2010 7:15 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
I have two tables
city
region

and 4 classes
City
SpecialCity extends City
Region
SpecialRegion extends Region

Some cities have regions, others do not. Some cities belong to SpecialRegions others just to Regions

I want to get all SpecialCities and Cities that belong to a SpecialRegion.

Using Criteria I quickly ran into trouble so I went with hql.
The query I'm looking for is something like

Code:
select city0_.*, region1_.* from City city0_
left outer join Region region1_ on city0_.FK_regionID=region1_.regionId
where city0_.FK_CountryID=2
and (region1_.DTYPE='SPL' or city0_.DTYPE='SPL')


When I use the following hql I would expect to get the above
Code:
from City c left outer join c.region where c.country = ? and (c.region.class = SpecialRegion or c.class = SpecialCity)


However, I get this, resulting in effectively an inner join between region and city
Code:
select city0_.*, region1_.* from City city0_
left outer join Region region1_ on city0_.FK_regionID=region1_.regionId
cross join Region region2_
where city0_.FK_regionID=region2_.regionId
and city0_.FK_CountryID=2
and (region2_.DTYPE='SPL' or city0_.DTYPE='SPL')


Is this a mistake on my side? If so, how can I fix this?

Kind regards,

Marc


Top
 Profile  
 
 Post subject: Re: Hibernate generates unwanted cross join
PostPosted: Fri Jul 16, 2010 7:19 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hmm solved it:
Code:
from City c left outer join c.region r where c.country = ? and (r.class = URLRegion or c.class = URLCity)


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.