-->
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: inheritance and queries
PostPosted: Sat Oct 27, 2007 3:36 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I set up an inheritance tree with inheritance type JOINED. The parent object User is a pretty simple one. The Child one Vendor is more complex. So, when I do a

return getHibernateTemplate().find("from User where nickName=?", nickName);

the query actually shows that it tries to query the vendor table as well.

When I retrieve by id I get lots of LEFT OUTER JOINs. Etc. This seems very inefficient. Is there a way to make a find on User just query that table in stead of the child table as well?

I use Spring and Appfuse.

Mapping documents:
@Entity(name = "User2")
@Table(name = "Users")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn
@DiscriminatorValue(value = "USER")
public class User extends BaseObject {

private Long userId;
private String nickName, password, email, ipAddress;
private Date lastLogin;
private Set<Offer> favourites;
private boolean blocked;

etcetc

@Entity
@Table(name="Vendors")
@DiscriminatorValue(value="VENDOR")
@JoinColumn(name="FK_UserID", nullable=false, updatable=false)
public class Vendor extends User implements IUser {

private Long vendorId;

private City city;
private Region province;
private Country country;
private String address,zipCode, skype, phone;
private Set<Offer> offers;
private int numOffers;

etcetc


The generated SQL (show_sql=true):
Hibernate: select user0_.userId as userId17_, user0_.blocked as blocked17_, user
0_.email as email17_, user0_.ipAddress as ipAddress17_, user0_.lastLogin as last
Login17_, user0_.nickName as nickName17_, user0_.password as password17_, user0_
1_.address as address19_, user0_1_.FK_CityID as FK9_19_, user0_1_.FK_CountryID a
s FK7_19_, user0_1_.numOffers as numOffers19_, user0_1_.phone as phone19_, user0
_1_.FK_ProvinceID as FK8_19_, user0_1_.skype as skype19_, user0_1_.zipCode as zi
pCode19_, case when user0_1_.userId is not null then 1 when user0_.userId is not
null then 0 end as clazz_ from Users user0_ left outer join Vendors user0_1_ on
user0_.userId=user0_1_.userId where user0_.nickName=?

Hibernate: select user0_.userId as userId17_6_, user0_.blocked as blocked17_6_,
user0_.email as email17_6_, user0_.ipAddress as ipAddress17_6_, user0_.lastLogin
as lastLogin17_6_, user0_.nickName as nickName17_6_, user0_.password as passwor
d17_6_, user0_1_.address as address19_6_, user0_1_.FK_CityID as FK9_19_6_, user0
_1_.FK_CountryID as FK7_19_6_, user0_1_.numOffers as numOffers19_6_, user0_1_.ph
one as phone19_6_, user0_1_.FK_ProvinceID as FK8_19_6_, user0_1_.skype as skype1
9_6_, user0_1_.zipCode as zipCode19_6_, case when user0_1_.userId is not null th
en 1 when user0_.userId is not null then 0 end as clazz_6_, city1_.cityId as cit
yId8_0_, city1_.city as city8_0_, city1_.FK_CountryID as FK6_8_0_, city1_.FK_reg
ionID as FK5_8_0_, city1_.shortCode as shortCode8_0_, city1_.timeZone as timeZon
e8_0_, country2_.countryId as countryId9_1_, country2_.country as country9_1_, c
ountry2_.countryCode as countryC3_9_1_, region3_.regionId as regionId16_2_, regi
on3_.FK_CountryID as FK3_16_2_, region3_.region as region16_2_, country4_.countr
yId as countryId9_3_, country4_.country as country9_3_, country4_.countryCode as
countryC3_9_3_, region5_.regionId as regionId16_4_, region5_.FK_CountryID as FK
3_16_4_, region5_.region as region16_4_, country6_.countryId as countryId9_5_, c
ountry6_.country as country9_5_, country6_.countryCode as countryC3_9_5_ from Us
ers user0_ left outer join Vendors user0_1_ on user0_.userId=user0_1_.userId lef
t outer join Cities city1_ on user0_1_.FK_CityID=city1_.cityId left outer join C
ountries country2_ on city1_.FK_CountryID=country2_.countryId left outer join Re
gions region3_ on city1_.FK_regionID=region3_.regionId left outer join Countries
country4_ on user0_1_.FK_CountryID=country4_.countryId left outer join Regions
region5_ on user0_1_.FK_ProvinceID=region5_.regionId left outer join Countries c
ountry6_ on region5_.FK_CountryID=country6_.countryId where user0_.userId=?



Kind regards,

Marc


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.