-->
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: Problem with multiple composite-id mapping
PostPosted: Fri Nov 04, 2005 12:07 pm 
Newbie

Joined: Fri Nov 04, 2005 11:34 am
Posts: 1
I'm working on a legacy table structure which contains following structure. I cannot change the structure of this nor can I add fields.

Between brackets the names of the properties within the persitent classes.

Table tttadv100000 Package : T$cpac (PackageId), t$dsca (Description)
Table tttadv101000 Module : t$cmod (ModuleId), t$cpac (PackageId), t$dsca Description
Table tttadv420000 Table: t$cmod (ModuleId), t$cpac (PAckageid), t$flno (Tableno)

I have following mappings:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class  name="Scholle.BaanDictionary.Business.Tools.BaanPackage, Scholle.BaanDictionary.Business"
         table="BAANDB.TTTADV100000" mutable="false">
      <cache usage="read-write"/>
      <composite-id>
         <key-property name="PackageId" column="T$CPAC" />
      </composite-id>
      <property name="Description" column="T$DSCA" type="String" />
      <set inverse="true" lazy="true" name="Modules">
         <key column="T$CPAC"/>
         <one-to-many class="Scholle.BaanDictionary.Business.Tools.BaanModule, Scholle.BaanDictionary.Business"/>
      </set>
   </class>
</hibernate-mapping>


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class  name="Scholle.BaanDictionary.Business.Tools.BaanModule, Scholle.BaanDictionary.Business"
         table="BAANDB.TTTADV101000" mutable="false">
      <cache usage="read-write"/>
      <composite-id >
         <key-property name="ModuleId" column="T$CMOD"/>
         <key-many-to-one name="Package" column="T$CPAC" />
      </composite-id>
      <property name="Description" column="T$DSCA" type="String" />
      <property name="StatusLine" column="T$STAL" type="String" />
      <set name="Table" inverse="true" lazy="true" >
         <key>
            <column name="T$CMOD"/>
            <column name="T$CPAC"/>
         </key>
         <one-to-many class="Scholle.BaanDictionary.Business.Tools.BaanTable, Scholle.BaanDictionary.Business"/>
      </set>
   </class>
</hibernate-mapping>


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class  name="Scholle.BaanDictionary.Business.Tools.BaanTable, Scholle.BaanDictionary.Business"
         table="BAANDB.TTTADV420000" mutable="false">
      <cache usage="read-write"/>
      <composite-id >
         <key-many-to-one name="Module">
            <column name="T$CMOD" not-null="true"/>
            <column name="T$CPAC" not-null="true" unique-key="true" />
         </key-many-to-one>
         <key-property name="TableId" column ="T$FLNO" />
      </composite-id>
      <property name="Customer" column="T$CUST" type="String" />
      <property name="Version" column="T$VERS" type="String" />
      <property name="ModifyDate" column="T$DATE" type="String" />
      <property name="RelationType" column="T$RELA" type="String" />
      <property name="DeleteReferenceMessage" column="T$RFMD" type="String" />
      <property name="UpdateReferenceMessage" column="T$RFMU" type="String" />
      <property name="HelpTopic" column="T$TXTC" type="String" />
      <property name="MandatatoryAudit" column="T$ZA_AUDT" type="String" />      
   </class>   
</hibernate-mapping>


The code only needs to read the legacy tables.

I have made all classes serializable and methods Equals and GetHashCode have overrides.

The reference from module to package works fine, however with the reference from Table to Module I get "No row with the given identifier exists: Scholle.BaanDictionary.Business.Tools.BaanModule, of class: Scholle.BaanDictionary.Business.Tools.BaanModule".

Changing the keys to only contain properties and move the associations out in a separate many-to-one section gives comparable results.

I call this with following code:


Code:
DataAccessManager manager = new DataAccessManager("Scholle.BaanDictionary.Business");
BaanTableFacade tableFacade = new BaanTableFacade(manager);
System.Collections.IList tables = tableFacade.GetAll();
dataGridView1.DataSource = tables;
dataGridView1.Show();


Am I making design errors within the mapping file and is there a better way to do this kind of key structures e.g. separate identity classes?

_________________
Charles Korthout
Scholle Europe B.V


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.