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.  [ 12 posts ] 
Author Message
 Post subject: Need One on One Training
PostPosted: Mon Oct 16, 2006 12:18 am 
Newbie

Joined: Fri Sep 29, 2006 11:13 pm
Posts: 10
I will apologize up front if I am not allowed to ask this on this forum. I will understand if it is deleted.

I am a college student that needs to learn NHibernate for a class project. I have been attempting to teach myself by reviewing various sample applications and tutorials. I have been unsuccessful in getting NHibernate to work for me.

How can I find someone that is willing to assist me with some one on one training?

suh136@psu.edu

_________________
Thank you,
Susan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 3:34 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Hi,

i can help you in solving problems but spoon-feeding is not possible for me. Just let me know ur requirement.

-Regards,
Deepak


Top
 Profile  
 
 Post subject: My current status
PostPosted: Mon Oct 16, 2006 6:34 am 
Newbie

Joined: Fri Sep 29, 2006 11:13 pm
Posts: 10
Thank you for your offer. This is where I am at.

I have downloaded the sample app at the following location:

http://blog.benday.com/archive/2005/10/25/3054.aspx

It seems pretty straighforward and I am trying to use the same basic structure for my project. I substitute my class definitions and mapping files but do not get the same results.

The most recent error message that I am dealing with is:
"Could not find a setter for property 'ID' in class 'Lifecloud.Business.User'"

The 'ID' for this class is "User_ID" and I have a "set" declared in the class definition. When I went in to the class definition and initialized it to "0" it got past the User class but then I received the same error for my next class that I have:

"Could not find a setter for property 'ID' in class 'Lifecloud.Business.Billing"

When I initialize the Billing_ID to zero, it just returns the same error.

Would it be possible for you to review my code? I could put it out on my personal webpage for you to download.

Let me know how you would like me to proceed.

_________________
Thank you,
Susan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 7:01 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Please provide me your class files as well as mapping files.


Top
 Profile  
 
 Post subject: Class & Mapping files
PostPosted: Mon Oct 16, 2006 7:45 am 
Newbie

Joined: Fri Sep 29, 2006 11:13 pm
Posts: 10
I am going into class right now. I will be able to forward those files to you in about 1.5 hours.

I appreciate your help.

_________________
Thank you,
Susan


Top
 Profile  
 
 Post subject: Class & Mapping Files
PostPosted: Mon Oct 16, 2006 10:57 am 
Newbie

Joined: Fri Sep 29, 2006 11:13 pm
Posts: 10
This is my User class file with the mapping file listed at the end. The extra 'bag' tags at the end represent the other tables that I will be working with in the database. I currently have them commented out.

Code:

User.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace Lifecloud.Business
{
    public class User :BusinessBase
    {

        #region Member Variables

        private int m_userid = 0;
        private string m_firstname = "";
        private string m_midinitial = "";
        private string m_lastname = "";
        private string m_emailaddress = "";
        private string m_status = "";
        private string m_logonid = "";
        private string m_gender = "";
        private string m_age = "";
        private DateTime m_datecreated = DateTime.Now;
        private DateTime m_datemodified = DateTime.Now;

        ////private IList m_billings; //for future enhancement


        #endregion


        #region Constructors
        /// <summary>
        /// This is a placeholder constructor for NHibernate.
        /// A no-argument constructor must be available for NHibernate to create the object.
        /// Be sure to call the "primary" constructor so the collections get wired up correctly.
        /// </summary>

        public User()
        {
        }

        #endregion

        #region Properties

        public virtual int User_ID
        {
            get { return m_userid; }
            set { m_userid = value; }
        }

        public virtual string FirstName
        {
            get { return m_firstname; }
            set {
                if (value == null)
                {
                    throw new ArgumentNullException("FirstName cannot be set to NULL");
                }
                m_firstname = value;
            }
        }

        public virtual string MidInitial
        {
            get { return m_midinitial; }
            set { m_midinitial = value; }
        }

        public virtual string LastName
        {
            get { return m_lastname; }
            set {
                if (value == null)
                {
                    throw new ArgumentNullException("LastName cannot be set to null");
                }
                m_lastname = value;
            }
        }

        public virtual string EmailAddress
        {
            get { return m_emailaddress; }
            set {
                if (value == null)
                {
                    throw new ArgumentNullException("EmailAddress cannot be set to null");
                }
                m_emailaddress = value;
            }
        }

        public virtual string Status
        {
            get { return m_status; }
            set { m_status = value; }
        }

        public virtual string LogonID
        {
            get { return m_logonid; }
            set { m_logonid = value; }
        }

        public virtual string Gender
        {
            get { return m_gender; }
            set {
                if (value == null)
                {
                    throw new ArgumentNullException("Gender cannot be set to null");
                } m_gender = value;
            }
        }
        public virtual string Age
        {
            get { return m_age; }
            set { m_age = value; }
        }

        public virtual DateTime DateCreated
        {
            get { return m_datecreated; }
            set { m_datecreated = value; }
        }

        public virtual DateTime DateModified
        {
            get { return m_datemodified; }
            set { m_datemodified = value; }
        }
       
        public override int Key
        {
            get { return this.User_ID; }
        }

        #endregion

        #region Methods


        #endregion

    }
}

User.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Lifecloud.Business.User, Lifecloud.Business" table="User_ID">
    <id name="ID" type="int" column="User_ID" unsaved-value="0">
      <generator class="native" />
    </id>

    <property name="FirstName" column="FirstName" />
    <property name="MidInitial" column="MidInitial" />
    <property name="LastName" column="LastName" />
    <property name="EmailAddress" column="EmailAddress" />
    <property name="Status" column="Status" />
    <property name="LogonID" column="LogonID" />
    <property name="Gender" column="Gender" />
    <property name="Age" column="Age" />
    <property name="DateCreated" column="DateCreated" />
    <property name="DateModified" column="DateModified" />

    <!--<bag name="Billings" lazy="true" table="Billing_ID" inverse="true"
       access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.Billing_ID, Lifecloud.Core" />
    </bag>-->

    <!--<bag name="ExerciseStats" lazy="true" table="ExerciseStats_ID" inverse="true"
     access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
    </bag>

    <bag name="CurStats" lazy="true" table="CurStats_ID" inverse="true"
     access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
    </bag>

    <bag name="TargetStats" lazy="true" table="TargetStats_ID" inverse="true"
     access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
    </bag>

    <bag name="MentalStats" lazy="true" table="MentalStats_ID" inverse="true"
     access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
    </bag>

    <bag name="Recipes" lazy="true" table="Recipe_ID" inverse="true"
     access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
    </bag>

    <bag name="Exercises" lazy="true" table="Exercise_ID" inverse="true"
     access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
    </bag>

    <bag name="Articles" lazy="true" table="Article_ID" inverse="true"
     access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
    </bag>

    <bag name="WorkOutPlans" lazy="true" table="WorkOutPlans_ID" inverse="true"
     access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" >
      <key column="User_ID" />
      <one-to-many class="Lifecloud.Core.Domain.User_ID, Lifecloud.Core" />
    </bag>-->

  </class>
</hibernate-mapping>



This is the Billing class with the mapping files at the end.

Code:
Billing.cs

using System;
using System.Collections.Generic;
using System.Text;


namespace Lifecloud.Business
{
    public class Billing
    {

        #region Member Variables

        private int m_billingid = 0;
        private int m_userid;
        private string m_billaddress1;
        private string m_billaddress2;
        private string m_billcity;
        private string m_billstate;
        private string m_billzip;
        private string m_homephone;
        private string m_workphone;
        private string m_mobilephone;
        private string m_billemail;
        private string m_creditcardtype;
        private string m_creditcardnum;
        private string m_ccexpiration;
        private string m_ccverify;
        private DateTime m_datecreated;
        private DateTime m_datemodified;


        #endregion


        #region Constructors
        /// <summary>
        /// This is a placeholder constructor for NHibernate.
        /// A no-argument constructor must be avilable for NHibernate to create the object.
        /// Be sure to call the "primary" constructor so the collections get wired up correctly.
        /// Instead of passing null to the primary constructor, I'd recommend passing a
        /// "null object": http://www.cs.oberlin.edu/~jwalker/nullObjPattern/.
        /// (But passing null keeps things very simple for the example.)
        /// </summary>

        public Billing() { }


        #endregion


        #region Properties

        /// <summary>
        /// Sets up parent/child relationship add/remove scaffolding.  So if a child is
        /// added to a parent, the parent automatically gets added to the child, and vice versa.
        /// </summary>

        public int Billing_ID
        {
            get { return m_billingid; }
            set { m_billingid = value; }
        }

        public int User_ID
        {
            get { return m_userid; }
            set { m_userid = value; }
        }

        public string BillAddress1
        {
            get { return m_billaddress1; }
            set { m_billaddress1 = value; }
        }

        public string BillAddress2
        {
            get { return m_billaddress2; }
            set { m_billaddress2 = value; }
        }

        public string BillCity
        {
            get { return m_billcity; }
            set { m_billcity = value; }
        }

        public string BillState
        {
            get { return m_billstate; }
            set { m_billstate = value; }
        }

        public string BillZip
        {
            get { return m_billzip; }
            set { m_billzip = value; }
        }

        public string HomePhone
        {
            get { return m_homephone; }
            set { m_homephone = value; }
        }

        public string WorkPhone
        {
            get { return m_workphone; }
            set { m_workphone = value; }
        }

        public string MobilePhone
        {
            get { return m_mobilephone; }
            set { m_mobilephone = value; }
        }

        public string BillEmail
        {
            get { return m_billemail; }
            set { m_billemail = value; }
        }

        public string CreditCardType
        {
            get { return m_creditcardtype; }
            set { m_creditcardtype = value; }
        }

        public string CreditCardNum
        {
            get { return m_creditcardnum; }
            set { m_creditcardnum = value; }
        }

        public string CCExpiration
        {
            get { return m_ccexpiration; }
            set { m_ccexpiration = value; }
        }

        public string CCVerify
        {
            get { return m_ccverify; }
            set { m_ccverify = value; }
        }

        public DateTime DateCreated
        {
            get { return m_datecreated; }
        }

        public DateTime DateModified
        {
            get { return m_datemodified; }
        }


        #endregion


        #region Methods

        #endregion

    }
}


Billing.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="Lifecloud.Business.Billing, Lifecloud.Business" table="Billing">
    <id name="ID" type="int" column="Billing_ID" unsaved-value="0">
      <generator class="native" />
    </id>

    <property name="User_ID" column="User_ID" />
    <property name="BillAddress1" column="BillAddress1" />
    <property name="BillAddress2" column="BillAddress2" />
    <property name="BillCity" column="BillCity" />
    <property name="BillState" column="BillState" />
    <property name="BillZip" column="BillZip" />
    <property name="HomePhone" column="HomePhone" />
    <property name="WorkPhone" column="WorkPhone" />
    <property name="MobilePhone" column="MobilePhone" />
    <property name="BillEmail" column="BillEmail" />
    <property name="CreditCardType" column="CreditCardType" />
    <property name="CreditCardNum" column="CreditCardNum" />
    <property name="CCExpiration" column="CCExpiration" />
    <property name="CCVerify" column="CCVerify" />
    <property name="DateCreated" column="DateCreated" />
    <property name="DateModified" column="DateModified" />

  </class>
</hibernate-mapping>


The program stops running in this class module at the line noted. This is not the entire class (let me know if you ned it). I included the complete error message at the end of the code.

Code:

NHibernateHttpModule.cs

        protected static ISessionFactory CreateSessionFactory()
        {
            Configuration config;
            ISessionFactory factory;

            config = new Configuration();

            if (config == null)
            {
                throw new InvalidOperationException("NHibernate configuration is null.");
            }

            config.Configure();

            factory = config.BuildSessionFactory(); <== This is the line that the following error points to.

NHibernate.PropertyNotFoundException was unhandled by user code
  Message="Could not find a setter for property 'ID' in class 'Lifecloud.Business.User'"
  Source="NHibernate"
  StackTrace:
       at NHibernate.Property.BasicPropertyAccessor.GetSetter(Type type, String propertyName)
       at NHibernate.Mapping.Property.GetSetter(Type clazz)
       at NHibernate.Persister.AbstractEntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
       at NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
       at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ISessionFactoryImplementor factory)
       at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings)
       at NHibernate.Cfg.Configuration.BuildSessionFactory()
       at Lifecloud.DataAccess.NHibernateHttpModule.CreateSessionFactory() in

C:\Lifecloud\Lifecloud.DataAccess\NHibernateHttpModule.cs:line 85
       at Lifecloud.DataAccess.NHibernateHttpModule.get_CurrentFactory() in

C:\Lifecloud\Lifecloud.DataAccess\NHibernateHttpModule.cs:line 126
       at Lifecloud.DataAccess.NHibernateHttpModule.CreateSession() in

C:\Lifecloud\Lifecloud.DataAccess\NHibernateHttpModule.cs:line 140
       at Lifecloud.DataAccess.NHibernateHttpModule.get_CurrentSession() in

C:\Lifecloud\Lifecloud.DataAccess\NHibernateHttpModule.cs:line 187
       at Lifecloud.DataAccess.BaseDataAccess..ctor() in C:\Lifecloud\Lifecloud.DataAccess\BaseDataAccess.cs:line 20
       at Lifecloud.BusinessFacade.UserFacade.GetUser() in C:\Lifecloud\Lifecloud.BusinessFacade\UserFacade.cs:line 40
       at ViewUsers.PopulateUsers() in c:\Lifecloud\Lifecloud.WebUI\ViewUsers.aspx.cs:line 29
       at ViewUsers.Page_Load(Object sender, EventArgs e) in c:\Lifecloud\Lifecloud.WebUI\ViewUsers.aspx.cs:line 22
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

_________________
Thank you,
Susan


Top
 Profile  
 
 Post subject: Mapping files: are column names case sensitive?
PostPosted: Mon Oct 16, 2006 11:32 am 
Newbie

Joined: Fri Sep 29, 2006 11:13 pm
Posts: 10
The column names in my mapping files are not the same case as the filed names in my daatabase.

Is the mapping file case-sensitive?

_________________
Thank you,
Susan


Top
 Profile  
 
 Post subject: Re: Mapping files: are column names case sensitive?
PostPosted: Mon Oct 16, 2006 11:44 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
suh136 wrote:
The column names in my mapping files are not the same case as the filed names in my daatabase.

Is the mapping file case-sensitive?


You map
Code:
<id name="ID" ...>...</id>


but Your property is named User_ID.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: My next issue...
PostPosted: Tue Oct 17, 2006 12:44 pm 
Newbie

Joined: Fri Sep 29, 2006 11:13 pm
Posts: 10
Thanks Gert for pointing that out to me.

Not only was I not using the same variable names but my data table column names were in lowercase and I had them mapped as upper/lowercase. I made both changes and I have progressed through my previous stumbling blocks.

I understand a little better how NHibernate is mapping the database. What I need to understand now is how to take a person's logonid, go to the User table and get their userid, and then go to the other tables in my database and bring back all the records that have that userid. The userid is the foreign key in all the other tables.

I was starting out only using the user and billing tables until I understood how NHibernate works.

_________________
Thank you,
Susan


Top
 Profile  
 
 Post subject: Re: My next issue...
PostPosted: Tue Oct 17, 2006 12:53 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
suh136 wrote:
Thanks Gert for pointing that out to me.

Not only was I not using the same variable names but my data table column names were in lowercase and I had them mapped as upper/lowercase. I made both changes and I have progressed through my previous stumbling blocks.

I understand a little better how NHibernate is mapping the database. What I need to understand now is how to take a person's logonid, go to the User table and get their userid, and then go to the other tables in my database and bring back all the records that have that userid. The userid is the foreign key in all the other tables.

I was starting out only using the user and billing tables until I understood how NHibernate works.


Usually the ObjectId-s are not used but references to other objects.

i.e. in Billing class, instead of having
Code:
        public int User_ID
        {
            get { return m_userid; }
            set { m_userid = value; }
        }

you have
Code:
        public User User
        {
            get { return m_user; }
            set { m_user = value; }
        }


And You map it with <many-to-one>

The properties of <bag> mappings are of type IList<Billing> for example.

And those properties are loaded auto-magically by NHibernate.

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: Cannot implicitly convert type ......
PostPosted: Tue Oct 17, 2006 4:24 pm 
Newbie

Joined: Fri Sep 29, 2006 11:13 pm
Posts: 10
I added this to the User.cs

Code:
           public IList <Billing> Billings
           {
                  get
                  {
                      if (m_billings == null)
                      {
                             m_billings = new ArrayList();
                      }

Line 142:                   return m_billings;
              }
                  set
                  {
Line 146:                    m_billings = value;
                  }
           }

I added this to the User.hbm.xml

Code:

    <bag name="Billings" inverse="false" cascade="save-update" table="billing_id" >
      <key column="user_id"></key>
      <one-to-many class="Lifecloud.Business.Billing, Lifecloud.Business"></one-to-many>
    </bag>



I added this to the Billing.cs
Code:

           private int m_user;

           public User User
           {
Line 67:            get { return m_user; }
Line 68:            set { m_user = value; }
           }


I added this to Billing.hbm.xml:
Code:

    <many-to-one name="BilledBy" column="user_id" class="Lifecloud.Business.User, Lifecloud.Business"
         access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" />



When I built the solution, it generated the following errors:

Code:

Error   1   Cannot implicitly convert type 'int' to 'Lifecloud.Business.User'   Billing.cs   67   26
Error   2   Cannot implicitly convert type 'Lifecloud.Business.User' to 'int'   Billing.cs   68   28



Error   3   Cannot implicitly convert type 'System.Collections.IList' to 'System.Collections.Generic.IList<Lifecloud.Business.Billing>'. An explicit conversion exists (are you missing a cast?)   User.cs   142   24
Error   4   Cannot implicitly convert type 'System.Collections.Generic.IList<Lifecloud.Business.Billing>' to 'System.Collections.IList'. An explicit conversion exists (are you missing a cast?)   User.cs   146   30


Am I missing some other declarations having to do with the IList?

_________________
Thank you,
Susan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 4:57 pm 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
try with
Code:
private User m_user;

and
Code:
private IList<Billing> m_billings;
..
m_billings = new List<Billing>();


Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.