Thread:
 session.Save(newUser) 
 rhm002   23 Oct 2007, 15:16 
 Re: session.Save(newUser) 
 Nandem   22 Jan 2008, 16:55 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: rhm002 (23 Oct 2007, 15:16) Replies: 1, Views: 2302
Subject: session.Save(newUser)
Good Day

I have build this example and it works until the session.Save(newUser) 
when an exception occures. 

NHibernate.MappingException "Unknown Entry Class: User"

Code:
            Configuration cfg = new Configuration();
            cfg.AddAssembly("nhibernate");

            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession();
            ITransaction transaction = session.BeginTransaction();

            User newUser = new User();
            newUser.Id = "joe_cool";
            newUser.UserName = "Joseph Cool";
            newUser.Password = "abc123";
            newUser.EmailAddress = "joe (at) cool (dot) com";
            newUser.LastLogon = DateTime.Now;

            session.Save(newUser);
            transaction.Commit();
            session.Close();

User.cs
using System;

public class User
{
    private string id;
    private string userName;
    private string password;
    private string emailAddress;
    private DateTime lastLogon;

    public User()
    {
    }

    public string 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; }
    }

    public string EmailAddress
    {
        get { return emailAddress; }
        set { emailAddress = value; }
    }

    public DateTime LastLogon
    {
        get { return lastLogon; }
        set { lastLogon = value; }
    }
}

User.hbm.xls
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="User" table="users">
    <id name="Id" column="LogonId" type="String" length="20">
      <generator class="assigned" />
    </id>
    <property name="UserName" column="Name" type="String" length="40"/>
    <property name="Password" type="String" length="20"/>
    <property name="EmailAddress" type="String" length="40"/>
    <property name="LastLogon" type="DateTime"/>
  </class>
</hibernate-mapping>

if anyone can assist me, it would be greatly apreciated

Ronald
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]