I am having trouble figuring out how to create a mapping document for my particular situation.
Before I go into the problem, I am using NHibernate 1.2.1 with Spring.NET 1.1.1.
The problem:
I have two tables, that have a simple one to many relationship. The tables are as follows:
Code:
InteractiveBooks:
=================
InteractiveBookID (PK)
InteractiveBookName
Public
Active
PrintableURL
UseStyle
...
InteractiveBookSections:
========================
InteractiveBookSectionID (PK)
InteractiveBookID (FK)
BookSectionName
OutlineLevel
Sequence
...
Pretty simple. The issue is on the code-side (this is something that I cannot change because it is this way throughout our system, and this change would be a
huge project).
The classes that contain the Interactive Book and Section information are as follows (in pseudo code without the details):
Code:
class oInteractiveBook
{
private oInteractiveBookSections bookSections;
// ... All info from InteractiveBooks table ...
}
class oInteractiveBookSections
{
private Collection<oInteractiveBookSection> bookSectionCollection;
}
class oInteractiveBookSection
{
// ... All info from InteractiveBookSections table ...
}
One attempted solution:I tried creating the hbm.xml files as such:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<!-- Make sure to set the build action for this file to "Embedded Resource" -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="field.camelcase">
<class name="oInteractiveBook, BusinessTypes" table="InteractiveBooks" lazy="false">
<id name="MlInteractiveBookID" column="InteractiveBookID" type="long">
<generator class="native"/>
</id>
<property name="MsInteractiveBookName" column="InteractiveBookName" type="String(100)"/>
<property name="MbPublic" column="Public" type="Boolean"/>
...
<bag name="MoBookSections" table="InteractiveBookSections" lazy="false">
<key column="InteractiveBookID"/>
<one-to-many class="oInteractiveBookSection, BusinessTypes"/>
</bag>
</class>
</hibernate-mapping>
- and -
Code:
<?xml version="1.0" encoding="utf-8" ?>
<!-- Make sure to set the build action for this file to "Embedded Resource" -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="field.camelcase">
<class name="oInteractiveBookSection, BusinessTypes" table="InteractiveBookSections" lazy="false">
<id name="MlInteractiveBookSectionID" column="InteractiveBookSectionID" type="long">
<generator class="native"/>
</id>
<property name="MlInteractiveBookID" column="InteractiveBookID" type="long"/>
...
<property name="msDescription" column="Description" type="String(300)"/>
</class>
</hibernate-mapping>
However, this does not work. I get the following error:
Code:
NHibernate.PropertyNotFoundException : Could not find field 'moBookSections' in class 'oInteractiveBook'
Obviously NHibernate needs to populate the oInteractiveBookSections object here too, and I am not telling it how to with these mapping files. The problem is, I cannot figure out how. Anyone have any idea what I should do?
Thanks for your help.