I downloaded NHibernate and think it is very promising. I'm a experienced user of PostgresSQL and so i want to use NHibernate with PostgreSQL.
Connecting works fine butting mapping failes, first the error then my code:
(I'm using a dutch version of Sharp Develop so some messages contain Dutch expressions).
Uitzondering NHibernate.MappingException werd in de debugger verworpen:
NHibernate.Users.hbm.xml(6,12): XML validation error: The 'table' attribute is not declared.堀ಸ
As you can see below, there is a table attribute in my "param" tag at line 6 just as the documentation tells.
---------------------------------------------------------------------------------
The code in my main class:
Code:
Configuration cfg = new Configuration();
cfg.Properties.Add("hibernate.connection.driver_class","NHibernate.Driver.NpgsqlDriver");
cfg.Properties.Add("hibernate.dialect","NHibernate.Dialect.PostgreSQLDialect");
cfg.Properties.Add("hibernate.connection.provider","NHibernate.Connection.DriverConnectionProvider");
cfg.Properties.Add("hibernate.connection.connection_string","Server=localhost;Database=xxxx;User ID=xxxx;Password=xxxx;Encoding=UNICODE");
cfg.AddAssembly("NHibernate");
cfg.AddClass(typeof(Users));
ISessionFactory sessionFactory = cfg.BuildSessionFactory();
ISession currentSession = sessionFactory.OpenSession();
currentSession.Close();
Code in my User object:
Code:
namespace NHibernate
{
public class Users
{
private int id;
private string username;
private string password;
public Users()
{
}
public int Id
{
get { return id;}
set { id = value; }
}
public string Username
{
get { return username;}
set { username = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
}
}
My mapping file (referenced as embedded resource):
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.Users" table="users">
<id name="Id" column="user_id">
<generator class="sequence">
<param table="sequence">users_user_id_seq</param>
</generator>
</id>
<property name="Username" column="username">
</property>
<property name="Password" column="password">
</property>
</class>
</hibernate-mapping>
My table:
Code:
Column | Type | Modifiers
---------------------------------------------------------------------------------------------------
user_id | integer | not null default nextval('users_user_id_seq'::regclass);
username | character varying(25) | not null
password | character varying(32) | not null
----------------------------------------------------------------------------------
I hope to get to some solution soon so i can experiment any futher with NHibernate.
Thanks in advanced!