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.  [ 9 posts ] 
Author Message
 Post subject: "Unknown Entity Class" Error with Quick Start Guid
PostPosted: Fri Nov 09, 2007 10:12 am 
Newbie

Joined: Fri Nov 09, 2007 10:01 am
Posts: 15
Hello

I am trying the NHibernate Quick Start Guide Example in VB.Net with a SQL Server 2005 database. All files are put under the root where the project is named "NHibernateProject"

I use a very basic entity bsUser:

Code:
Public Class bsUser
    Private m_id As String
    Private m_userName As String

    Public Property Id() As String
        Get
            Return m_id
        End Get
        Set(ByVal value As String)
            m_id = value
        End Set
    End Property
    Public Property UserName() As String
        Get
            Return m_userName
        End Get
        Set(ByVal value As String)
            m_userName = value
        End Set
    End Property
End Class


I am using a SQL Server 2005 database with:
- Database name: NHibernate
- One table: dbo.users
- Two columns in this table: LogonID (nvarchar(20)), Name (nvarchar(40))
The corresponding User.hbm.xml-file looks like this:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="NHibernateProject.bsUser, NHibernateProject" table="users">
    <id name="Id" column="LogonId" type="String" length="20">
      <generator class="assigned" />
    </id>
    <property name="UserName" column="Name" type="String" length="40"/>
  </class>
</hibernate-mapping>


My app.config file:

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.MsSql2005Dialect"
    />
    <add
      key="hibernate.connection.driver_class"
      value="NHibernate.Driver.SqlClientDriver"
    />
    <add
      key="hibernate.connection.connection_string"
      value="Server=localhost\SQLEXPRESS$BIE;initial catalog=NHibernate;Integrated Security=SSPI"
    />
  </nhibernate>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>
</configuration>


Now I am trying to get an action by putting following code behind a Button-event, and I am continuously getting an "Unknown entity class" Error. Can anyone see what I am overlooking?

Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myConfiguration As Configuration = New Configuration
        Dim factory As ISessionFactory = myConfiguration.BuildSessionFactory
        Dim session As ISession = factory.OpenSession
        Dim transaction As ITransaction = session.BeginTransaction
        myConfiguration.AddAssembly("NHibernateProject")
        Dim myUser As New bsUser
        myUser.Id = "ELKBE"
        myUser.UserName = "John Miles"
        session.Save(myUser)
        transaction.Commit()
        session.Close()
        MessageBox.Show("The test was successful.")
    End Sub


Last edited by bennieke on Fri Nov 09, 2007 10:21 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: "Unknown Entity Class" Error with Quick Start
PostPosted: Fri Nov 09, 2007 10:19 am 
Newbie

Joined: Fri Nov 09, 2007 10:01 am
Posts: 15
----


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 10, 2007 2:32 am 
Beginner
Beginner

Joined: Mon Oct 22, 2007 5:44 am
Posts: 28
Hi bennieke,


I assume that the problem is the mapping file name. Try to rename the mapping file to bsUser.hbm.xml and NOT User.hbm.xml.

Moreover, try to be more specific and detail ALL the operations you did including the following:
1 - Did you embed the mapping file?
2 - Where does the error occur?
3 - You can attach the error trace.

Dan Yahav

_________________
dyahav


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 10, 2007 5:05 pm 
Newbie

Joined: Fri Nov 09, 2007 10:01 am
Posts: 15
Dear dyahav

I put the project in a Zip-file at the following location: http://users.telenet.be/sheepke/NHibernateProject.zip.

Could this be useful to trace the error?

Thank you in advance for your help. ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 10, 2007 5:19 pm 
Newbie

Joined: Fri Nov 09, 2007 10:01 am
Posts: 15
---


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 10, 2007 5:55 pm 
Beginner
Beginner

Joined: Mon Oct 22, 2007 5:44 am
Posts: 28
Hi,

Try to do the following:
Right-click on the.hbm.xml file and set the Build Action property to “Embeded Resource” .
From now the .NET will compile the mapping file into the Assembly.DLL.

I hope it will be helpful...

Dan Yahav

_________________
dyahav


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 11, 2007 9:59 am 
Newbie

Joined: Fri Nov 09, 2007 10:01 am
Posts: 15
I already set the Build Action property to "Embedded Resource".

I deleted the file and recreated it, but this did not help either.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 11, 2007 10:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
You did not tell NHibernate where to find the mapping file(s). Add a call to myConfiguration.AddAssembly() after you created the Configuration.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 11, 2007 6:18 pm 
Newbie

Joined: Fri Nov 09, 2007 10:01 am
Posts: 15
You are right, karlchu. I had to maintain the order as described in the Quick Start Guide, and I obviously didn't.

Beneath that, I had to put the modifiers in my entity class virtual. In VB.Net, you obtain this by using the keyword 'Overridable'.

Code:
Public Class bsUser
    Private m_LogonID As String
    Private m_Name As String

    Public Overridable Property LogonID() As String
        Get
            Return m_LogonID
        End Get
        Set(ByVal value As String)
            m_LogonID = value
        End Set
    End Property
    Public Overridable Property Name() As String
        Get
            Return m_Name
        End Get
        Set(ByVal value As String)
            m_Name = value
        End Set
    End Property
End Class


For those who are interested in the outcome of my test, I put the project at the following location: http://users.telenet.be/sheepke/NHibernateProject-v2.zip. It only puts the LogonID- and Name-data of the specified SQL Server 2005-datatable into a DataGridView by using NHibernate. You are also allowed to enter a new user. Remember the Primary Key at the LogonID-column.

Thank you both, dyahav and karlchu, for your help. It is highly appreciated. ;-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.