Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:1.1
The test fixture does this:
ISession session = factory.OpenSession();
Language lang = (Language) session.Find("from Language as l where l.Name = ?", "english", NHibernateUtil.String);
Language.cs:
public class Language
{
private int _LanguageId;
private string _Name;
private string _Description;
private bool _Active;
public int LanguageId
{
get { return _LanguageId; }
set { _LanguageId = value; }
}
public string Name
{
get { return _Name; }
set { _Name = value; }
}
public string Description
{
get { return _Description; }
set { _Description = value; }
}
public bool Active
{
get { return _Active; }
set { _Active = value; }
}
}
}
Language.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="ScotiaOCAPDAL.Language, ScotiaOCAPDAL" table="Language">
<id name="LanguageId" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name" />
<property name="Description"/>
<property name="Active" />
</class>
</hibernate-mapping>
sql out:
NHibernate: select language0_.LanguageId as LanguageId, language0_.Name as Name, language0_.Description as Descript3_, language0_.Active as Active from Language language0_ where (language0_.Name=@p0)
@p0 = 'english'
The error message in NUnit:
ScotiaOCAPDAL.LanguageFixture.LoadName : System.InvalidCastException : Specified cast is not valid.
What am i doing wrong in the session.Find() step. I get it to work accepting Int32 but can't get it to go for string.
I got it to go with createCriteria, but I want to see why session.Find is failing like this.
Any help much appreciated.