Hi,
I am a new buddy using NHibernate. When i am trying to save the object, it showing me the fallowing exception.
"could not insert: [Users.User][SQL: INSERT INTO [dbo].[users] (UserName, Password, EmailAddress) VALUES (?, ?, ?)]"} System.Exception {NHibernate.ADOException}
the inner exception is :
{"Cannot insert the value NULL into column 'LoginID', table 'EHM.dbo.users'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."} System.Exception {System.Data.SqlClient.SqlException}
my mapping file is as below
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Users"
assembly="Users">
<class name="Users.User" table="[dbo].[users]">
<id name="Id" column="LoginID" >
<generator class="native" />
</id>
<property name="UserName" column="UserName" />
<property name="Password" column="Password" />
<property name="EmailAddress" column="EmailAddress" />
</class>
</hibernate-mapping>
Here is my actual code
try
{
cfg.AddAssembly("Users");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
//Users.User newuser = new Users.User();
User newuser = new User();
newuser.Id = "sree";
newuser.UserName = "Srikanth";
newuser.Password = "kanth";
newuser.EmailAddress = "sree@yahoo.com";
session.Save(newuser); /* Here i am getting the problem*/
transaction.Commit();
session.Close();
}
Here is my persistant class:
public class User
{
private string id;
private string userName;
private string password;
private string emailAddress;
public User()
{
}
public virtual string Id
{
get { return id; }
set { id = value; }
}
public virtual string UserName
{
get { return userName; }
set { userName = value; }
}
public virtual string Password
{
get { return password; }
set { password = value; }
}
public virtual string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
}
Please any one help me in fixing the exception.
Thank u very much in advance.
Bye,
srikanth.
|