-->
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: composite-id while mapping legacy data
PostPosted: Tue Sep 20, 2005 8:27 am 
Newbie

Joined: Thu May 12, 2005 10:40 am
Posts: 16
I've to map an existing db with a 'one to one' relation between two tables and composite-keys.
I played around for a few days now, but i can't find any good samples for relations with composite keys and how to deal if there a no null values on no associations.
There are a few thing's i'm not sure, would be a great help, if anybody could share a few sugggestions with me.

first for the 'legacy-tables':

table t_cando
Code:
Id varchar
Part int
..
Date DateTime
Person varchar


table t_todo
Code:
Id varchar
...
Date DateTime
Job varchar
...
CanDoId varchar
CanDoPart int


Id and Part together are the primry key for t_cando.
Only Id is the primary key for t_todo.

the system defines a 'job match' by assigning a 'cando' to a 'todo'.
therefore CanDoId and CanDoPart get the aproriate Key-Values from cando-jobs. if there's no association CanDoId is '' and CanDoPart has Value 0.

because i couldn't find the ability with one-to-one and composite-keys in dokumentation, i tryed to map this as follows.

Code:
<class name="CanDo" table="t_cando">
<composite-id name="kCanDo" class="kCanDo">
<key-property name="Id1" type="String" column="Id"/>
<key-property name="Id2" type="Int32" column="Part"/>
</composite-id>
...
<property column="Date" type="DateTime" name="Date" not-null="true"/>
<property column="Person" type="String" name="Person" not-null="true"/>
...


Code:
<class name="ToDo" table="t_todo">
<id name="Id" column="Id" type="String" length="255" />
<many-to-one name="CanDo" class="CanDo">
  <column name="CanDoId" />
  <column name="CanDoPart" />
</many-to-one>
...
<property column="Date" type="DateTime" name="Date" not-null="true"/>
<property column="Job" type="String" Name="Job" not-null="true"/>
...


because i can't change the column names or the application, i've to live with these things.
For perfomance it's necessary to get all data for assigned and unassigned ToDo's in one query with the CanDo's.
fe. ' from ToDo d where d.Date = '01.09.2005' ' should read all necessary data for CanDos and ToDos (in a outer-join?)
so i've got a few questions:

    * Is this mapping appropritate, or are there better solutions for this scenario ? (collections?)
    * Ho do the CanDoId and CanDoPart Columns of t_todo find there right parts Id and Part within t_cando ? There seems to be no ability to specify the names of the corrsponding columns within the other table. Do the columns have to be in the same order as the key-property name definitions ? column doesnt't accept something like property name =
    SOLVED: the order is as expected, relevant
    * the system does'nt use null values for values in CanDoId and CanDoPart. CanDoId is '' and CanDoPart is 0 if there is no 'job assignment'. Can i specify this anywhere ? Doing a scan-query 'from ToDo d where d.Date = '01.09.2005' on gives me somtimes NHibernate.ObjectNotFoundException: No row with the given identifier exists: I think this i because empty assignments don't use null within these fields, so it might try to find a cando where ther is no. but i'm not sure about this. How can i solve this (using a formula translating column value from '' to null ? if yes, does this need to be done on any column of the composite-id ?, trick around with collections ?)


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.