-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to make a set(?) use a property instead of the class id?
PostPosted: Thu Oct 09, 2003 11:29 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
How can you make a Collection (set/list/array/etc.) use a field other than the class's id, as the collection's key? I'm asking because I'm only seeing references to the <key> tag being stuck on the class.id, not the class.someFieldName. The forums, reference PDF, mapping DTD and examples aren't giving me (at least not clearly) what I need.

Can someone point me in the right direction?

The simple details are this:
An order (id field = mysql native generator) has order_items. Each order_item (id field = mysql native generator) needs to be looked up via the field batchid, which is a property of the order and a property of the order_items. Unfortunately, everything I've tried has stuck the order.id in the order_item.batchid field when I need it to be the order.batchid used in the order_item.batchid field.

Thanks for any suggestions,
David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2003 9:31 am 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
Why do you even need a key for the collection. Just stick the parent batchid into the child batchid before the save.

Hope this helps. If not, you might post the code and mappings

Jeff


Top
 Profile  
 
 Post subject: Can't use the parent batchid, it's a legacy db without that
PostPosted: Fri Oct 10, 2003 11:01 am 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
Jeff,

My DB is a legacy db and I need to have the order_detail based off the batchid. The problem is that both classes have an id that is mysql-auto-generated and need to link off the property field batchid. I don't see anything in the mapping DTD (not that I'm good at reading a DTD) suggesting specifying a field other than the <id../> for collections to use as their lookup key.

Do you know of any way to make the collection key off a <property.../> or any field for that matter which isn't the class's <id.../> field?

Below are the relevant snippets from my hibernate mapping.

Thanks,
David

<class name="db.order" table="purchasers">
<id name="id"
type="long"
unsaved-value="0"
column="id">
<generator class="assigned"/>
</id>
<property name="batchid" type="long" column="batchid"/>
<property name="ccnumber" type="string" column="ccnumber" length="20"/>
<property name="ccmon" type="string" column="ccmon" length="20"/>
<property name="ccyear" type="string" column="ccyear" length="5"/>
<set name="items" lazy="true" cascade="all">
<key column="batchid"/>
<index column="id"/>
<one-to-many class="org.hawaiifun.model.v4.PurchaseDetail"/>
</set>
</class>

<class name="db.orderDetail" table="purchases">
<id name="id"
type="long"
unsaved-value="0"
column="id">
<generator class="native"/>
</id>
<property name="batchid" type="long" column="batchid"/>
<property name="lineitem" type="int" column="lineitem"/>
etc....
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2003 11:29 am 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
db.order / purchasers
- id (PK - assigned)
- batchid
- ccnumber
- ccmon
- ccyear
- items

db.orderDetail / purchases
- id (PK - generated
- batchid
- lineitem

Quote:
The problem is that both classes have an id that is mysql-auto-generated and need to link off the property field batchid.


I don't get what you mean here but perhaps I'm just slow.

What's the FK to db.order in db.orderDetail? batchid? If so then what is db.order.id? You can't have 2 different PK's.

Jeff


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