-->
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.  [ 3 posts ] 
Author Message
 Post subject: Retrieve collection of values
PostPosted: Sat Mar 12, 2005 12:45 pm 
Newbie

Joined: Tue Feb 01, 2005 10:20 pm
Posts: 10
Hi,

I'm having a problem to create an sql query to retrieve values from
the tables mapped as I'm showing in the code below.

How can I make a query for table "workType"?

Thanks for help.

Hibernate version:2.x

Mapping documents:
<class name="User" table="User">
<id name="id" column="user_id" type="long" unsaved-value="null">
<generator class="identity"/>
</id>
<discriminator column="USER_TYPE" type="string"/>
<property name="status" column="user_status" type="boolean" />

<bag name="phoneList" lazy="true" cascade="all">
<key column="user_id"/>
<one-to-many class="PhoneNo"/>
</bag>

<subclass name="Tech" discriminator-value="Tech">
<property name="techCode" column="tech_techCode" type="string" />

<bag name="workTypeList" table="workType" lazy="true">
<key column="type_id"/>
<element column="tech_workType" type="string"/>
</bag>

<bag name="workAreaList" lazy="true" cascade="save-update">
<key column="user_id"/>
<one-to-many class="WorkArea"/>
</bag>
</subclass>

</class>



Code between sessionFactory.openSession() and session.close():

Example: (I've tried different things)
"from Tech t, WorkType w where (t.user_type ='tech') and (w.tech_workType = 'work type 1')"



Name and version of the database you are using: MySql


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 13, 2005 4:21 am 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
SELECT w
FROM Tech t
INNER JOIN WorkType w
WHERE w.tech_workType = 'work type 1'

I can't really figure out why yours doesn't work, but that's how I would aproach the problem. You shouldn't have to specify t.user_type ='tech' since that's your discriminator.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 13, 2005 1:18 pm 
Newbie

Joined: Tue Feb 01, 2005 10:20 pm
Posts: 10
pkulak wrote:
SELECT w
FROM Tech t
INNER JOIN WorkType w
WHERE w.tech_workType = 'work type 1'

I can't really figure out why yours doesn't work, but that's how I would aproach the problem. You shouldn't have to specify t.user_type ='tech' since that's your discriminator.



Thanks for help.

I was able to retrieve values by using similar code:

"from Tech t left join fetch t.workTypeList type where type in (:types)"


Regards,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.