-->
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: Mapping a map where the subclass key is not the parent key
PostPosted: Fri Aug 26, 2005 11:28 am 
Newbie

Joined: Mon Apr 26, 2004 5:17 pm
Posts: 13
Hibernate version: 3.0.5

Name and version of the database you are using: db2 udb 8.1

Mapping documents:

<class
name="TSOrderSet"
table="TS_ORDER_SET"
schema="TS"
lazy="false"
>
<id
name="a_OrderId"
column="ORDERID"
type="string"
unsaved-value="null"
>
<generator class="sequence" >
<param name="sequence" >TS.ORDER_ID_SEQ</param>
</generator>
</id>
<property
name="a_SetId"
column="SET_ID"
type="string"
not-null="true"
/>
<map
name="a_DescriptionMap"
table="TS_SET_DESCRIPTIONS"
schema="TS"
cascade="none"
lazy="false"
>
<key
column="DESCRIPTION_ID"
/>
<index
column="LANGUAGE_ID"
type="string"
/>
<element
column="DESCRIPTION"
type="string"
not-null="true"
/>
</map>
</class>


Hibernate now expects that in my descriptiontable the orderId is in the Column DESCRIPTION_ID of the table TS_SET_DESCRIPTIONS. But
I want the SET_ID to be my key of the descriptiontable. How can I tell this to the map declaration. Looked in the Book and the online documentation.

Thanks for any help!


Top
 Profile  
 
 Post subject: guessing
PostPosted: Fri Aug 26, 2005 2:15 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It is kind of standard modeling practice for foreign keys to refer to a primary key of related table, it simply has a lot of sense.

For one, if you will ever need to change value of SET_ID you do not need to update dependent objects because they are linked to surrogate key a_OrderId.


However, I suspect (just guessing), that you have a set definition table where SET_ID is the primary key, and in the TSOrder object you want to have set of descriptions associated with the set. If that is the case then I recommend to have a SomeSet class which will have normal map mapping and on the TSOrder have a field of SomeSet type, that will be mapped simply as many-to-one.

Then in the TSOrder object the desired map will be accessible as
tfOrder.getSet().getDescriptionsMap(). H will take care of the rest.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 26, 2005 4:52 pm 
Newbie

Joined: Mon Apr 26, 2004 5:17 pm
Posts: 13
yeah, your probably right. actually its a (order - lineItem - Item) Relationship. For some reasons I was subclassing lineItem from Item, which was getting me in Trouble(I wanted to get all Items, but instead I was getting all LineItems by the command: session.load(item.class)) I think I should handle it like you said.

Thanks for your advice.

By the way: Is it possible to store an object in two different tables? Is this the discriminator thing?


Top
 Profile  
 
 Post subject: something like that
PostPosted: Fri Aug 26, 2005 5:04 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Maybe this:
http://www.hibernate.org/hib_docs/v3/re ... edsubclass

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.