I am getting a weird error when using NHibernate. And I don't know what is causing this error.
I am new to the whole Visual Studio and NHibernate, but not to Hibernate. I used Hibernate in the past in Java projects.
Any help would be appreciated in pointing me where my error is.
I am using Visual Studio 2008 SP1 with Mysql 5.1.
Below is the code I am using.
Main program:
Code:
Configuration cfg = new Configuration();
cfg.Configure(Assembly.GetExecutingAssembly(), "K.TestCase.Database.hibernate.cfg.xml");
ISessionFactory factory = cfg.BuildSessionFactory(); <== Here the error is thrown
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.driver_class">
NHibernate.Driver.MySqlDataDriver
</property>
<property name="connection.connection_string">
Server=localhost;Database=K;User ID=K;Password=K;
</property>
<property name="dialect">
NHibernate.Dialect.MySQL5Dialect
</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
</property>
<!-- mapping files -->
<mapping resource="K.TestCase.Database.HibernateClass.hbm.xml" assembly="K.TestCase.Database" />
</session-factory>
</hibernate-configuration>
HibernateClass.cs
Code:
namespace K.TestCase.Database
{
class HibernateClass
{
private int id;
private string text1;
private string text2;
public virtual int Id
{
get { return id; }
set { id = value; }
}
public virtual string Text1
{
get { return text1; }
set { text1 = value; }
}
public virtual string Text2
{
get { return text2; }
set { text2 = value; }
}
public override string ToString()
{
return this.id + " " + this.text1 + " " + this.text2;
}
}
}
HibernateClass.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="K.TestCase.Database.HibernateClass, K.TestCase.Database" table="hibernate">
<id name="Id" column="id" type="Int32">
<generator class="identity" />
</id>
<property name="Text1" column="text1" type="String" length="50" />
<property name="Text2" column="text2" type="String" length="50"/>
</class>
</hibernate-mapping>
Table:
Code:
DROP TABLE IF EXISTS `k`.`hibernate`;
CREATE TABLE `k`.`hibernate` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`text1` text NOT NULL,
`text2` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;