Hi,
I'm completely new to nhibernate, i've got some things working now but i'm strugling with a one-to-many relation.
2 classes : Artikel (article in eng) and Leverancier (supplier in eng).
1 article has one supplier, 1 supplier has more articles. Many-to-one is going fine.
Class Artikel:
Code:
using System;
namespace NHibernate.Examples.QuickStart
{
public class Artikel
{
private long mArtikelnummer;
private string mNaam;
private long mHoofdgroep;
private long mSubgroep;
private long mBTWgroep;
private double mVerkoopprijs;
private string mOpmerking;
private bool mLeverbaar;
private DateTime mAanmaakdatum;
private Leverancier mLeverancier;
public Artikel()
{
}
public long Artikelnummer
{
get { return mArtikelnummer; }
set { mArtikelnummer = value; }
}
public string Naam
{
get { return mNaam; }
set { mNaam = value; }
}
public long Hoofdgroep
{
get { return mHoofdgroep; }
set { mHoofdgroep = value; }
}
public long Subgroep
{
get { return mSubgroep; }
set { mSubgroep = value; }
}
public long BTWgroep
{
get { return mBTWgroep; }
set { mBTWgroep = value; }
}
public double Verkoopprijs
{
get { return mVerkoopprijs; }
set { mVerkoopprijs = value; }
}
public string Opmerking
{
get { return mOpmerking; }
set { mOpmerking = value; }
}
public bool Leverbaar
{
get { return mLeverbaar; }
set { mLeverbaar = value; }
}
public DateTime Aanmaakdatum
{
get { return mAanmaakdatum; }
set { mAanmaakdatum = value; }
}
public Leverancier Leverancier
{
get { return mLeverancier; }
set { mLeverancier = value; }
}
}
}
Class Leverancier:
Code:
using System;
using System.Collections;
namespace NHibernate.Examples.QuickStart
{
public class Leverancier
{
private long mLeverancierID;
private string mNaam;
private string mAdres;
private string mWoonplaats;
private IList mArtikelen = new ArrayList(); // One-To-Many Relationship
public Leverancier()
{
}
public long LeverancierID
{
get { return mLeverancierID; }
set { mLeverancierID = value; }
}
public string Naam
{
get { return mNaam; }
set { mNaam = value; }
}
public string Adres
{
get { return mAdres; }
set { mAdres = value; }
}
public string Woonplaats
{
get { return mWoonplaats; }
set { mWoonplaats = value; }
}
public IList Artikelen
{
get { return this.mArtikelen;}
}
// ......
}
}
Mapping file:
Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernate.Examples.QuickStart.Artikel, WindowsApplication3" table="Artikel">
<id name="Artikelnummer" column="Artikelnummer">
<meta attribute="test" />
<column name="Artikelnummer" />
<generator class="assigned" />
</id>
<property name="Naam" column="Naam" />
<property name="Hoofdgroep" column="Hoofdgroep" />
<property name="Subgroep" column="Subgroep" />
<property name="BTWgroep" column="Btwgroep" />
<property name="Verkoopprijs" column="Verkoopprijs" />
<property name="Opmerking" column="Opmerking" />
<property name="Leverbaar" column="Leverbaar" />
<property name="Aanmaakdatum" column="Aanmaakdatum" />
<many-to-one name="Leverancier" column="Leverancier" class="NHibernate.Examples.QuickStart.Leverancier,WindowsApplication3"/>
</class>
<class name="NHibernate.Examples.QuickStart.Leverancier, WindowsApplication3" table="Leverancier" discriminator-value="?">
<id name="LeverancierID" column="LeverancierID">
<meta attribute="test" />
<column name="LeverancierID" />
<generator class="assigned" />
</id>
<property name="Naam" column="Naam" />
<property name="Adres" column="Adres" />
<property name="Woonplaats" column="Woonplaats" />
<bag name="Artikelen" cascade="all" access="nosetter.camelcase" lazy="false" inverse="true">
<key column="Artikelnummer" />
<one-to-many class="NHibernate.Examples.QuickStart.Artikel,WindowsApplication3" />
</bag>
</class>
</hibernate-mapping>
Now when I run the program:
ISessionFactory factory = cfg.BuildSessionFactory();
generates:
An unhandled exception of type 'NHibernate.PropertyNotFoundException' occurred in nhibernate.dll
Additional information: Could not find field 'artikelen' in class 'System.Object'
I just know it must be a very stupid mistake somewhere, but I just can't find it. It seems nhibernate is looking for the property "artikelen" in system.object instead of the Atricle Class..?
I didn't find any simular error on the forum or internet...
thanks very much for your time,
bbloemen