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?