Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hello !
I have used Hibernate in some J2EE development in the past, and now, I hve to try to use Nhibernate in a DOT.NET dev.
So, I have dowloaded NHibernate, and I actually try to use it in Visual Studio 2003 for an aspx/c# development. For that, I follow the instructions from
http://www.hibernate.org/362.html , and I am in the step 5. But that doesn't work, I have an error:
" NHibernate.PropertyNotFoundException: Could not find a setter "
Mapping documents:
My XML, located in Mappings , called , County.hbm.xml :
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ppwebsite.Mappings.County, ppwebsite" table="tblCounty">
<id name="idCounty" column="CountyID" type="System.Int32">
<generator class="assigned"/>
</id>
<property name="nameCounty" column="County" not-null="true" type="String" length="40" />
</class>
</hibernate-mapping>
----------------------
My classe, in the same directory:
using System;
namespace ppwebsite.Mappings
{
public class County
{
private int idCounty;
private string nameCounty;
public County()
{
}
public County(int idCountyNew, string nameCountyNew)
{
this.idCounty=idCountyNew;
this.nameCounty=nameCountyNew;
}
//first try to make a setter
public int Id
{
get { return idCounty; }
set { idCounty = value; }
}
//second try to make a setter
public void setIdCounty(int idCountyNew)
{
this.idCounty=idCountyNew;
}
public int getIdCounty()
{
return this.idCounty;
}
public void setNameCounty(string nameCountyNew)
{
this.nameCounty=nameCountyNew;
}
public string getNameCounty()
{
return this.nameCounty;
}
}
}
Code between sessionFactory.openSession() and session.close():
in my aspx.cs :
......
using NHibernate;
using NHibernate.Cfg;
......
private void Page_Load(object sender, System.EventArgs e)
{
Configuration cfg = new Configuration();
cfg.AddAssembly("ppwebsite");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
County c = new County();
c.setIdCounty(70);
c.setNameCounty("countyTest");
session.Save(c);
// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
}
Full stack trace of any exception that occurs:
Could not find a setter for property 'idCounty' in class 'ppwebsite.Mappings.County'
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: NHibernate.PropertyNotFoundException: Could not find a setter for property 'idCounty' in class 'ppwebsite.Mappings.County'
Source Error:
Line 58: Configuration cfg = new Configuration();
Line 59: cfg.AddAssembly("ppwebsite");
Line 60: ISessionFactory factory = cfg.BuildSessionFactory();
Line 61: ISession session = factory.OpenSession();
Line 62: ITransaction transaction = session.BeginTransaction();
Source File: c:\inetpub\wwwroot\ppwebsite\webform1.aspx.cs Line: 60
Stack Trace:
[PropertyNotFoundException: Could not find a setter for property 'idCounty' in class 'ppwebsite.Mappings.County']
NHibernate.Property.BasicPropertyAccessor.GetSetter(Type type, String propertyName)
NHibernate.Mapping.Property.GetSetter(Type clazz)
NHibernate.Persister.AbstractEntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory)
NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ISessionFactoryImplementor factory)
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings)
NHibernate.Cfg.Configuration.BuildSessionFactory()
ppwebsite.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ppwebsite\webform1.aspx.cs:60
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
Name and version of the database you are using:
I use SQL server, but I can use it correctly without HHibernate, so it shouldn't be the problem
Did I made something wrong ? I mean, I have followed the instructions from "NHibernate Quick Start Guide"
http://www.hibernate.org/362.html , so I should at least can run my soft !!!!
Thanks for the people who will answer me.
Rgds,
Stef