views:

828

answers:

0

Hi

Have the mapping as shown below. this is from a leagcy db so have no control over changing the structure. The File record in some circumstances will not have a link to the DISPLAY3 table. Every file has a link to the DISPLAY2 table. However if the File.DISPLAy3 field is null then is does not have a link to the DISPLAY3 only the DISPLAY2 table (qas section_code, display1 and display2 are not null). When loading the FILE object and inspecting the sql generated, the file record is queried from the DB, then DISPLAY2, then it attempts to query DISPLAY3, but as FILE.DISPLAY3 is null, it can't find any record and fails. I have amended the mapping file adding not-found="ignore"etc but it does not seem to help.

However while not files have DISPLAY3 records, DISPLAY3 will all have files and need to be able to load the tree that way as well so need this many-to-one and one-to-many relationship though in my case it should be many-to-one or none.

Any ideas would be greatly appreciated..

(have removed the < from all lines the xml below so it can all be seen if it looks odd)

hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
class name="Test.File,Test" table="FILE" lazy="true">
id name="FileId" column="FILE_ID" type="int">
generator class="assigned" />
/id>
property type="DateTime" name="OpeningDate" column="OPENED" />
property type="DateTime" name="ClosingDate" column="SHUTDATE" />
many-to-one name="DISPLAY2Code" cascade="none" not-found="ignore" fetch="join" outer-join="true">
column name="SECTION_CODE" />
column name="DISPLAY1_CODE" />
column name="DISPLAY2_CODE" />
/many-to-one>
many-to-one name="DISPLAY3Code" cascade="none" not-found="ignore" fetch="join" outer-join="true">
column name="SECTION_CODE" />
column name="DISPLAY1_CODE" />
column name="DISPLAY2_CODE" />
column name="DISPLAY3_CODE" />
/many-to-one>
class>
`

hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> class name="Test.DISPLAY3,Test" table="DISPLAY3" lazy="false">
composite-id name="Id" class="Test.DISPLAY3Id,Test">
key-many-to-one name="SectionCode" class="Test.DISPLAY2,Test">
column name="SECTION_CODE" /> column name="DISPLAY1_CODE" />
column name="DISPLAY2_CODE" />
/key-many-to-one>
key-property name="DISPLAY3Code" column="DISPLAY3_CODE" type="string" />
/composite-id>
bag name="FkFilesDISPLAY3" inverse="true" lazy="true" cascade="all">
key>
column name="SECTION_CODE" />
column name="DISPLAY1_CODE" />
column name="DISPLAY2_CODE" />
column name="DISPLAY3_CODE" />
/key>
one-to-many class="Test.Files,TEST" />
/bag>
class>
`/hibernate-mapping>