-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Unknown entity class
PostPosted: Thu Apr 12, 2007 11:28 am 
Newbie

Joined: Thu Apr 12, 2007 10:44 am
Posts: 2
I have read the previous post and i have try, but i'm still in trouble with my class.

Here there are my files:

Form1.cs

Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
//
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Examples;
using NHibernate.Examples.QuickStart;

   /// <summary>
   /// Summary description for Form1.
   /// </summary>
   public class Form1 : System.Windows.Forms.Form
   {
      private System.Windows.Forms.Button btnStart;
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.ComponentModel.Container components = null;

      public Form1()
      {
         //
         // Required for Windows Form Designer support
         //
         InitializeComponent();

         //
         // TODO: Add any constructor code after InitializeComponent call
         //
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if (components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }

      #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         this.btnStart = new System.Windows.Forms.Button();
         this.SuspendLayout();
         //
         // btnStart
         //
         this.btnStart.Location = new System.Drawing.Point(96, 200);
         this.btnStart.Name = "btnStart";
         this.btnStart.TabIndex = 0;
         this.btnStart.Text = "Start";
         this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
         //
         // Form1
         //
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(292, 266);
         this.Controls.Add(this.btnStart);
         this.Name = "Form1";
         this.Text = "Form1";
         this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {
         Application.Run(new Form1());
      }

      private void button1_Click(object sender, System.EventArgs e)
      {
      
      }

      private void btnStart_Click(object sender, System.EventArgs e)
      {
         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@cool.com";
         newUser.LastLogon = DateTime.Now;

         // Comunichiamo ad Hibernate che questo oggetto deve essere salvato
         try
         {
            session.Save(newUser);
         }
         catch ( MappingException ex)
         {
            MessageBox.Show(ex.Message + " - " + ex.StackTrace);
         }
   
         // Commit dei cambiamenti al database e chiusera della ISession
         transaction.Commit();
         session.Close();
      }
   }




User.cs

Code:
using System;

namespace NHibernate.Examples.QuickStart
{
   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; }
      }       
   }
}




App.Config


Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section
      name="nhibernate"
      type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    />
  </configSections>

  <nhibernate>
    <add
      key="hibernate.connection.provider"
      value="NHibernate.Connection.DriverConnectionProvider"
    />
    <add
      key="hibernate.dialect"
      value="NHibernate.Dialect.MsSql2000Dialect"
    />
    <add
      key="hibernate.connection.driver_class"
      value="NHibernate.Driver.SqlClientDriver"
    />
    <add
      key="hibernate.connection.connection_string"
           value="Server='SSQLMB02\SVIL2';initial catalog='Northwind';Integrated Security=SSPI" />   
  </nhibernate>
</configuration>




User.hbm.xml

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
    <class name="NHibernate.Examples.QuickStart.User, NHibernate" 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>


Where's the error ???????
The hbm file is build as Embedded Resource.

I'm still looking for the error.


Top
 Profile  
 
 Post subject: Unknown Entity Class
PostPosted: Fri Apr 13, 2007 2:38 pm 
Newbie

Joined: Fri Apr 13, 2007 2:12 pm
Posts: 2
Hi lk312

To me it seems as if your code in the start button differs from how it is done in the NHibernate QuickStart. If you check with this documentation you will see that the Configure code looks a little different from yours.

Maybe this is helpful. I did get the very simple example from nhibernate_reference "QuickStart with IIS and Microsoft SQL Server" to work. I just had to change the properties to virtual properties.

Good luck
stigb


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 2:52 pm 
Newbie

Joined: Fri Apr 13, 2007 2:12 pm
Posts: 2
Below is how it is done in the above mentioned example:

Code:
public sealed class NHibernateHelper
{
    private const string CurrentSessionKey = "nhibernate.current_session";
    private static readonly ISessionFactory sessionFactory;
    static NHibernateHelper()
    {
        sessionFactory = new Configuration().Configure().BuildSessionFactory();
    }
    public static ISession GetCurrentSession()
    {
        HttpContext context = HttpContext.Current;
        ISession currentSession = context.Items[CurrentSessionKey] as ISession;
        if (currentSession == null)
        {
            currentSession = sessionFactory.OpenSession();
            context.Items[CurrentSessionKey] = currentSession;
        }
        return currentSession;
    }
    public static void CloseSession()
    {
        HttpContext context = HttpContext.Current;
        ISession currentSession = context.Items[CurrentSessionKey] as ISession;
        if (currentSession == null)
        {
            // No current session
            return;
        }
        currentSession.Close();
        context.Items.Remove(CurrentSessionKey);
    }
    public static void CloseSessionFactory()
    {
        if (sessionFactory != null)
        {
            sessionFactory.Close();
        }
    }
}


stigb


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 9:31 am 
Newbie

Joined: Thu Apr 12, 2007 10:44 am
Posts: 2
Sorry, but, what i have to do with this class ???


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:24 pm 
Newbie

Joined: Fri May 04, 2007 2:12 pm
Posts: 3
I have the same problem too.
It occur in the NHibernate class "SessionFactoryImpl", in the GetEntityPersister method.

public IEntityPersister GetEntityPersister(System.Type theClass)
{
IEntityPersister result = classPersisters[theClass] as IEntityPersister;
if (result == null)
{
throw new MappingException("Unknown entity class: " + theClass.FullName);
}
return result;
}

It get my class but result equal null.
Can sombody help?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 3:05 pm 
Newbie

Joined: Fri May 04, 2007 2:12 pm
Posts: 3
Set of .hbm.xml file Build Action property to Embedded resource do not avoid problem


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.