-->
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: Problem querying with joined-subclass
PostPosted: Thu Jun 16, 2005 12:03 pm 
Beginner
Beginner

Joined: Wed Jun 15, 2005 2:00 pm
Posts: 38
Hi,

I've just begun to explore the use of table-per-subclass mapping strategy via the joined-subclass element. Here's my set-up.

I have 2 POJO classes as follows:

1. User, with fields id and name, where id is the identity key.

2. Employee, which is a subclass of User with additional fields, employeeID and department.

I'm using SQL Server 2000, and am using Eclipse development environment. Here's my mapping configuration for the User class:-

Code:
<class name="User" table="MM_USERS">
      <id name="id" column="id" type="int" unsaved-value="null" length="5">
         <generator class="native"/>
      </id>
      <property name="name" column="name" type="string" length="50" not-null="true"/>
      
      <many-to-one name="community" column="communityID" not-null="false" class="Community" cascade="all" unique="true"/>
      <set name="memberships" table="MM_USERGROUPLINKS" cascade="none" order-by="name asc" where="" >
         <key column="userID" />
         <many-to-many class="Group" column="groupID" />
      </set>
      
      <joined-subclass name="Employee" table="MM_EMPLOYEE">
         <key column="personID"/>
         <property name="employeeID" column="employeeID" type="string" length="10" not-null="false" />
         <property name="department" column="department" type="string" length="30" not-null="false" />
      </joined-subclass>
   </class>


What I then did was to insert a test Employee via a standalone Hibernate-based Java application which I wrote, and this succeeded.

Then I tried to do the following HQL, and my Eclipse console shows that this is the query generated by Hibernate:

Code:
select u from User as u where u.id = 1

Hibernate: select user0_.id as col_0_0_ from MM_USERS user0_ where user0_.id=?
Hibernate: select user0_.id as id0_, user0_.name as name0_0_, user0_.communityID
as communit3_0_0_, user0_1_.employeeID as employeeID2_0_, user0_1_.department a
s department2_0_, case when user0_1_.personID is not null then 1 when user0_.id
is not null then 0 end as clazz_0_ from MM_USERS user0_ left outer join MM_EMPLO
YEE user0_1_ on user0_.id=user0_1_.personID where user0_.id=?


which is spot on.

However when I tried the following query, I got the results as follows:

Code:
select u from Employee as u where u.id = :id

Hibernate: select employee0_.personID as col_0_0_ from MM_EMPLOYEE employee0_ in
ner join MM_USERS employee0_1_ on employee0_.personID=employee0_1_.id where empl
oyee0_.personID=?


which is wrong since it didn't return all the fields for employee, but only returned the id.

Any ideas what I'm doing wrong here?

Thanks!


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.