-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: one-to-many mapping problem
PostPosted: Tue Aug 02, 2005 7:43 am 
Newbie

Joined: Tue Aug 02, 2005 7:30 am
Posts: 8
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 02, 2005 2:53 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 2:48 pm
Posts: 47
How did you organize your project? Did you make a separate class library for your domain classes or did you only make 1 project containing both the domain classes and the application?
If you made the separation, you might have forgotten to add a assembly reference to your class library.

Greets,
JackBigMac


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 3:54 pm 
Newbie

Joined: Tue Aug 02, 2005 7:30 am
Posts: 8
Hi thanks for your reply.
It's a very simple try-out project that contains all classes and the application. No external references except nhibernate.

grz!
bbloemen


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 4:48 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You are using nosetter.camelcase naming strategy, it means that for a property named Artikelen NHibernate looks for a field named artikelen, while your field is named mArtikelen so it can't find it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 5:43 pm 
Newbie

Joined: Tue Aug 02, 2005 7:30 am
Posts: 8
Thanks sergey, that indeed was the problem.
I'm gonna read the docs twice before moving on to the next step!
grz!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.