Hey guys,
I recently managed to convince my colleagues to use NHibernate for persistence. So now I have to deal with it, without knowing very much about using Hibernate. At the moment I've got a problem with my mapping. I want to attach several arguments to a monitor. The arguments have got a composite-id, which I think must have something to do with the problem as all other one-to-manys are working fine.
ARGUMENTCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Foo.Model.HArgument, SelmaDb" table="argument">
<composite-id name="HArgumentPK" class="Foo.Model.HArgumentPK">
<key-property name="MonitorId" column="monitor_id" type="integer"/>
<key-property name="Position" column="position" type="integer"/>
</composite-id>
<many-to-one name="Monitor" column="monitor_id" class="Foo.Model.HMonitor"/>
<property name="Value" column="value" type="String" length="255"/>
</class>
</hibernate-mapping>
MONITORCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Foo.Model.HMonitor, SelmaDb" table="monitor">
<id name="Id" column="id" type="Int32">
<generator class="identity" />
</id>
<many-to-one name="Client" column="client_id" class="Foo.Model.HClient"/>
<many-to-one name="Command" column="command_id" class="Foo.Model.HCommand"/>
<property name="Interval" column="interval" type="Int32"/>
<bag name="Arguments" cascade="none" lazy="true">
<key column="monitor_id"/>
<one-to-many class="Foo.Model.HArgument"/>
</bag>
</class>
</hibernate-mapping>
Skeleton classesCode:
public class HArgument
{
#region orm specific
public virtual HMonitor Monitor { get; set; }
public virtual int Position { get; set; }
public virtual string Value { get; set; }
#endregion
....
Code:
public class HMonitor
{
#region orm specific
public virtual int Id { get; set; }
public virtual HClient Client { get; set; }
public virtual HCommand Command { get; set; }
public virtual int Interval { get; set; }
public virtual IList<HArgument> Arguments { get; set; }
#endregion
.....
When i build the session factory I get the following error: "Association references unmapped class: Foo.Model.HArgument". If I don't use the <bag> Tag in the HMonitor.hbm.xml it seems to work fine (at least I get the app to run as it should).
I think the solution must be really easy, I just don't seem to get it right...
Thanks for your help in advance,
peace
Hybris