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.  [ 2 posts ] 
Author Message
 Post subject: Need Help urgently!! MappingException: Unknown Entity Class
PostPosted: Thu Aug 30, 2007 3:15 pm 
Newbie

Joined: Thu Aug 30, 2007 2:50 pm
Posts: 7
Hi, I am trying to create my first nhibernate(ver=1.2) app which the source code I took from the web.

basically, the application consists only 1 class mapped to a table in embedded firebird(ver=2.0) database, below are the files in my application:

-----------------------------User.cs--------------------------
using System;

namespace NHibernate.Examples.Quickstart
{
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 Passwords
{
get { return password; }
set { password = value; }
}

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

---------------------------app.config---------------------------
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>

<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<!-- Database connection settings -->
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>

<property name="connection.driver_class">
NHibernate.Driver.FirebirdClientDriver
</property>

<property name="connection.connection_string">
Database=User.FDB;
User=sysdba;
Password=masterkey;
ServerType=1
</property>

<property name="dialect">NHibernate.Dialect.FirebirdDialect</property>

<property name="show_sql">true</property>

<property name="cache.provider_class">
NHibernate.Cache.NoCacheProvider
</property>

<mapping file="User.hbm.xml"/>
</session-factory>
</hibernate-configuration>

<log4net debug="false">

<!-- Define some output appenders -->
<appender name="trace"
type="log4net.Appender.TraceAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>

<appender name="console"
type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>

<appender name="rollingFile"
type="log4net.Appender.RollingFileAppender,log4net" >

<param name="File"
value="log.txt" />
<param name="AppendToFile"
value="false" />
<param name="RollingStyle"
value="Date" />
<param name="DatePattern"
value="yyyy.MM.dd" />
<param name="StaticLogFileName"
value="true" />

<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern"
value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>

<!-- Setup the root category, add the appenders and set the default priority -->

<root>
<priority value="WARN" />
<appender-ref ref="console" />
</root>

<logger name="NHibernate.Bytecode.CodeDom">
<priority value="OFF" />
</logger>

<logger name="NHibernate.SQL">
<level value="OFF" />
</logger>

<logger name="NHibernate.Tool.hbm2ddl.SchemaExport">
<level value="WARN" />
</logger>
</log4net>
</configuration>

-------------------------------User.hbm.xml-------------------------
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.Examples.Quickstart.User,NHibernate.Examples" 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="Passwords" column ="Passwords" type="String" length="20"/>
<property name="EmailAddress" column="EmailAddress" type="String" length="40"/>
</class>
</hibernate-mapping>

-----------------------------UserTest.cs-------------------------------
//This is the main class to test the nhibernate mapping
using System;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using log4net;
using log4net.Config;

namespace NHibernate.Examples.Quickstart
{
class UserTest
{
static void Main(string[] args)
{
XmlConfigurator.Configure();
Configuration cfg = new Configuration();
cfg.Configure();
//new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Create(true, true);

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.Passwords = "abc123";
newUser.EmailAddress = "joe@cool.com";

// Tell NHibernate that this object should be saved
session.Save(newUser); <-- ERROR OCCURED HERE

// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();
}
}
}

I have tried everything such as: gone through the debugging process(using .NET 2005 debugging tool) and I have checked every property of the ISession, ISessionFactory and Configuration as well.

they seems to get mapped properly, however the error that occurs is like this: (I'll just dump the stack trace)
Message: "Unknown entity class: NHibernate.Examples.Quickstart.User"

StackTrace:
at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(Type theClass)
at NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass)
at NHibernate.Impl.SessionImpl.GetEntityPersister(Object obj)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at NHibernate.Examples.Quickstart.UserTest.Main(String[] args) in C:\Swin\NHibernate.Examples.Quickstart\NHibernate.Examples.Quickstart\UserTest.cs:line 22
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


I have set the build action of the "User.hbm.xml" to "Embedded Resource" as well. I googled a lot and I found nothing that mention we should generate the assembly file callled "NHibernate.Examples" (setting the "User.hbm.xml" itself to "Embedded Resource" doesn't seems to solve the problem, since the .NET compile will start looking for the assembly file called "NHibernate.Examples which I used inside the "User.hbm.xml")

Most of the suggestions mentioned in lots of forum regarding this problem, I have tried and none of them solve my problem :(.

If any of you have successfully mapped the class to the firebird db, please tell me. I need it urgently.

just as additional note, my application is not Web application is an Console Application. Most of the tutorial including the nhibernate_reference itself, only shows how to deal with Web application, thus the GetCurrentSession() implementation can't be adopted into my application.


Top
 Profile  
 
 Post subject: Re: Need Help urgently!! MappingException: Unknown Entity Cl
PostPosted: Thu Aug 30, 2007 9:37 pm 
Beginner
Beginner

Joined: Wed Aug 29, 2007 1:25 pm
Posts: 26
Location: Recife, PE, Brazil
try it

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Examples" namespace="NHibernate.Examples.Quickstart">
<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="Passwords" column ="Passwords" type="String" length="20"/>
<property name="EmailAddress" column="EmailAddress" type="String" length="40"/>
</class>
</hibernate-mapping>


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