-->
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: Creating a one-to-many relationship without the primary key.
PostPosted: Thu Jul 03, 2008 1:33 pm 
Newbie

Joined: Thu Jul 03, 2008 10:57 am
Posts: 2
I'm trying to generate a set of objects inside another object using a one-to-many relationship as follows:

<class name="Message" table="message">
<id name="recordId" column="record_id" type="int"/>
<property name="deviceId" column="device_id" type="string" />
<set name="workers">
<key column="device_id" />
<one-to-many class="Worker" />
</set>
</class>

<class name="Worker" table="worker">
<id name="workerId" column="worker_id" type="string" />
<property name="deviceId" column="device_id" type="string" />
</class>

The problem is whenever I do queries that involve the Message object, instead of referencing the device_id of the Message object, it passes the record_id.

What I really want it to do is this:
Select * From message Left Join worker on message.device_id = worker.device_id

along with my other query.

Is there any way to make this work?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 8:48 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, you're getting the identifier, as specified in the mapping file, so it's working as it's supposed to.

Why not just do a criteria query? It would make life so much easier, and it would allow you to work with your objects - you could just call the getRecordId or getMessageId or whatever method/property call that you want on the object returned by the Hibernate Session.

Here's a little tutorial I put together on working with one to may associations with Hibernate:

Mapping One-to-Many Associations with Hibernate3

And here's another little learning guide to quickly get you up to speed on the Hibernate Criteria API:

Examples of the Hibernate3 Criteria API: A Tutorial

Hope this help you out and gives you some ideas!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.