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.  [ 5 posts ] 
Author Message
 Post subject: "Unknown entity class: contact"
PostPosted: Fri May 05, 2006 7:05 am 
Newbie

Joined: Fri May 05, 2006 4:54 am
Posts: 14
Hi!

Can“t get Nhibernate working.

1. Loading hibernate.hbm.xml file is working.
2. Loading assembly with all the hbm files and classes are working
3. Sessionfactory initializing is going great.
4. But when I try to save the contact object I get: "Unknown entity class: contact"
Everything seems right!

Hibernate version: 1.0.2


Mapping documents: <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="Com.Business">
<class name="Contact" table="Contact" >
<id name="Id">
<column name="id" type="System.Int32" unsaved-value="0"/>
<generator class="native" />
</id>
<property name="FirstName"/>
<property name="LastName"/>
<property name="EMail"/>
<property name="TelePhone"/>
</class>
</hibernate-mapping>

//Hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >
<session-factory>
<!-- properties -->

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS;AttachDbFilename="C:\jobb\vs2005 projects\Com\Com.WebUI\App_Data\DB.mdf";Integrated Security=True;User Instance=True;Min Pool Size=2</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>

<!--
<property name="use_outer_join">true</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
-->
<!-- mapping files -->
<mapping assembly="Com.Business" />
<!--<mapping resource="Com.Business.Contact.hbm.xml" assembly="Com.Business" /> -->
</session-factory>

</hibernate-configuration>



Code between sessionFactory.openSession() and session.close():Contact contact = new Contact();
ISession session = HibernateHelper.GetCurrentSession();

ITransaction tx = session.BeginTransaction();

try
{
if (firstName != null)
{
contact.FirstName = firstName;
contact.LastName = lastName;
contact.EMail = email;
contact.TelePhone = telephone;



session.SaveOrUpdate(contact);

tx.Commit();
HibernateHelper.CloseSession();
}
}
catch (Exception ex)
{
//tx.Rollback();
Console.Write(ex);
throw ex;
}


Please help!!!

Toni


Top
 Profile  
 
 Post subject: Found the problem!
PostPosted: Sat May 06, 2006 2:13 am 
Newbie

Joined: Fri May 05, 2006 4:54 am
Posts: 14
The hbm.xml files needed to be set to embedded resource in properties


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 4:00 am 
Newbie

Joined: Fri May 05, 2006 11:27 am
Posts: 8
I have the same error with a similar code
Quote:
Configuration cfg = new Configuration();
cfg.AddAssembly("NorthwindNHibernate");

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

Employee newEmplyee = new Employee();


newEmplyee.FirstName = "Ema";
newEmplyee.LastName = "Ornella";
newEmplyee.HomePhone = "043400000";

session.Save(newEmplyee);

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

When I try to Save(newEmployee) I have the following exception:

Quote:
Error: NHibernate.MappingException: Unknown entity class: Examples.Northwind.Employee
at NHibernate.Impl.SessionFactoryImpl.GetPersister(Type theClass)
at NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass)
at NHibernate.Impl.SessionImpl.GetPersister(Object obj)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
at NHibernate.Impl.SessionImpl.Save(Object obj)
at NorthwindNHibernate.Form1.button1_Click(Object sender, EventArgs e) in C:\Project\NorthwindNHibernate\Form1.cs:line 65
'NorthwindNHibernate.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Transactions\2.0.0.0__b77a5c561934e089\System.Transactions.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'NorthwindNHibernate.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll
The thread 0x6dc has exited with code 0 (0x0).


I'm sure the xml file for the mapping is "Embedded Resource", so it doesn't seems this the problem.

Any help?
Thanks,
ema


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 3:57 am 
Newbie

Joined: Tue Mar 07, 2006 4:56 am
Posts: 17
Hi!

I just had the same problem... The class name was correct and the XML file was set to embedded resource... Check the filename of your XML file. I had it named "file.hmb.xml" instead of "file.hbm.xml" :o)

I guess that could be your problem too!

Regards, Marco...


Top
 Profile  
 
 Post subject: HI
PostPosted: Tue Feb 17, 2009 5:14 am 
Newbie

Joined: Tue Feb 17, 2009 5:07 am
Posts: 1
I just had the same problem... The class name was correct and the XML file was set to embedded resource...
Configuration config = new Configuration();set to Configuration config = new Configuration().Configure();
let program go to find hibernate.cfg.xml,hibernate.cfg.xml config is :

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="TestCleanSnowModel">
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.OracleDataClientDriver"</property>
<property name="connection.connection_string">user id=jkpt;data source=jkorasvr;password=designer;</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.Dialect.OracleDialect</property>

<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<!-- mapping files -->
<mapping assembly="TestCleanSnow" />
</session-factory>
http://www.cnblogs.com/abcdwxc/archive/ ... 92552.html


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