-->
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.  [ 4 posts ] 
Author Message
 Post subject: Exception : Unknown entity class
PostPosted: Wed Mar 28, 2007 11:14 am 
Newbie

Joined: Wed Mar 28, 2007 10:58 am
Posts: 2
Hello,

I have this exception (Unknown entity class) when I execute : session.Save(newUser,2)

I believe User.hbm.xml must be "embedded resource", but with Visual Web Developer 2005 Express, I can't do

thanks

my code :

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;

// Tell NHibernate that this object should be saved
session.Save(newUser,1);

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 6:19 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Please note I'm using Hibernate, not NHibernate, so take my advice with caution.
If User is not mapped as an entity, but as a component, then it's normal. You must save its container, it will propagate savings. If you don't want to be forced to work with the container, then map User directly as an entity.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 11:11 am 
Newbie

Joined: Wed Mar 07, 2007 10:59 pm
Posts: 6
hi, vince23
Normal nhibernate config file must be like this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="Domain">

<!-- DB2 9 -->
<!--
<property name="connection.connection_string">driver={IBM DB2 ODBC DRIVER};Database=PERMBASE;hostname=localhost;port=50000;protocol=TCPIP;uid=Administrator;pwd=myPassword</property>
<property name="connection.driver_class">NHibernate.Driver.OdbcDriver</property>
<property name="dialect">NHibernate.Dialect.DB2Dialect</property>
-->

<!-- MySQL 5 -->
<!--
<property name="connection.connection_string">Server=localhost;Database=PermissionBase;User Id=PB_DB_USER;Password=1234567890</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
-->

<!-- Oracle 10g -->
<!--
<property name="connection.connection_string">Data Source=CAIKELUN;User Id=PB_DB_USER;Password=1234567890;Integrated Security=no</property>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
-->

<!-- SQL Server 2000/2005 -->
<property name="connection.connection_string">Server=localhost;Database=PermissionBase;User Id=PB_DB_USER;Password=1234567890</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>

<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
<property name="cache.use_query_cache">true</property>
<property name="relativeExpiration">120</property>
<mapping assembly="Domain" />

</session-factory>
</hibernate-configuration>

Are you see "<mapping assembly="Domain" />"this node?
I guess the assembly that your give is work wrong or not incluede the entity "User"!
good luck!
my blog :
http://www.cnblogs.com/Roping
and you can refence this article
http://www.cnblogs.com/Roping/archive/2 ... 89805.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 30, 2007 2:54 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
If you can't embed the resource into an assembly then you'll need to tell the configuration to load the files from a filepath so the session factory can be built with your objects.

MIKE

_________________
If this helped...please remember to rate it!


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