-->
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: Table per subclass SQL question
PostPosted: Sun Nov 16, 2008 1:28 am 
Newbie

Joined: Sat Oct 07, 2006 4:44 pm
Posts: 4
jboss-seam-2.1.0.SP1 Hibernate version:3.3.2

Project is generated with seam-gen. Following setup works fine but I am confused with the generated SQL.

I have the following tables.
-------------------------------
User
Patient
Doctor
Supervisor

Respective hibernate objects
---------------------------------
@Entity
@Table(name = "user")
@Inheritance(strategy = InheritanceType.JOINED)
User

@Entity
@Table(name = "patient")
Patient extends User
// id is not defined here.

@Entity
@Table(name = "doctor")
Doctor extends User
// id not defined

@Entity
@Table(name = "supervisor")
Supervisor extends User
// id not defined

When I load Patient list, I see a join between a patient class and user class which totally makes sense. But when I view User list, I see the following SQL.

select
user0_.id as id0_,
user0_.email as email0_,
user0_.passwd as passwd0_,
user0_.first_name as first4_0_,
user0_.last_name as last5_0_,
user0_.gender as gender0_,
user0_.dob as dob0_,
user0_.phone as phone0_,
user0_.fax as fax0_,
user0_1_.contact_name as contact3_1_,
user0_1_.contact_phone as contact4_1_,
user0_1_.contact_email as contact5_1_,
user0_1_.contact_fax as contact6_1_,
user0_1_.display_order as display11_1_,
user0_2_.contact_name as contact3_2_,
user0_2_.contact_phone as contact4_2_,
user0_2_.contact_email as contact5_2_,
user0_2_.contact_fax as contact6_2_,
user0_2_.status as status2_,
user0_2_.display_order as display11_2_,
user0_3_.status as status6_,
user0_3_.contact_name as contact4_6_,
user0_3_.contact_phone as contact5_6_,
user0_3_.contact_email as contact6_6_,
user0_3_.contact_fax as contact7_6_,
case
when user0_1_.id is not null then 1
when user0_2_.id is not null then 2
when user0_3_.id is not null then 3
when user0_.id is not null then 0
end as clazz_
from
user user0_
left outer join
doctor user0_1_
on user0_.id=user0_1_.id
left outer join
patient user0_2_
on user0_.id=user0_2_.id
left outer join
supervisor user0_3_
on user0_.id=user0_3_.id limit ?

Why is it doing a left outer join with doctor, patient and supervisor entities when I load user list? Is this the normal behavior? If it is, what should I do to prevent the joins and only load user list? I guess this makes sense for other inheritance strategies.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.