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: Problem with mapping...
PostPosted: Fri Dec 11, 2009 3:00 pm 
Newbie

Joined: Fri Dec 11, 2009 2:55 pm
Posts: 5
well I'm newbie of NHibernate
when i executing my nhibernate example then i receive error but I also Set Embedded Resource Property to true of xml file

Code:
public class UserData{
public void CreateUserAndSaveToDatabase() {
User u = new User();
u.ForeName = "John";
u.SureName = "Smith";
using (ISession session = factory.OpenSession()) {
using (ITransaction transaction = session.BeginTransaction()) {
session.Save(u);
transaction.Commit();
}
}
ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();
}



Rises Exception at session.Save(u) NHibernate.MappingException: Unknown entity class: HibernateCollaborator.Core.User

what's the problem??
would you advice me anything to solve this problem


Top
 Profile  
 
 Post subject: Re: Problem with mapping...
PostPosted: Wed Dec 16, 2009 3:05 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post the mapping file and youf config file ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Problem with mapping...
PostPosted: Thu Dec 17, 2009 6:00 pm 
Newbie

Joined: Fri Dec 11, 2009 2:55 pm
Posts: 5
wolli wrote:
Can you post the mapping file and youf config file ?

Of course...


here is web.config...

Code:
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
Server=(local)\SQLEXPRESS; Database=HibernateCollaborator; Integrated Security=true; Pooling=true
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
</property>
<property name="show_sql">
false
</property>
</session-factory>
</hibernate-configuration>
</configSections>


and User.hbm.xml

Code:
<?xml version="1.0" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="HibernateCollaborator.Core" namespace="HibernateCollaborator.Core" default-access="property" default-cascade="none" default-lazy="false" auto-import="true" >
  <class name="User" table="Users" lazy="false">
    <id name="ID" column="ID" type="Int32" unsaved-value="0">
      <generator class="native" />
    </id>
    <property name="ForeName" type="string" length="30" not-null="false">
      <column name="ForeName" sql-type="varchar" length="30" not-null="false"/>
    </property>
    <property name="SureName" type="string"  not-null="false">
      <column name="SureName" sql-type="varchar" length="30" not-null="false"/>
    </property>
    <property name="Username" type="string"  not-null="false">
      <column name="Username" sql-type="varchar" length="30" not-null="false"/>
    </property>
    <property name="Password" type="string"  not-null="false">
      <column name="Password" sql-type="varchar" length="30" not-null="false"/>
    </property>
    <property name="Email" type="string"  not-null="false">
      <column name="Email" sql-type="varchar" length="30" not-null="false"/>
    </property>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Problem with mapping...
PostPosted: Fri Dec 18, 2009 3:03 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Ah, missed that in the first post:

ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();

is not enough. YOu have to somehow register the classes, either via the assembly (therefore you need "Embedded Resource") or each file on its own. You can do this in your code

http://nhforge.org/doc/nh/en/index.html#configuration-programmatic

or in the config file:
<session-factory>
... <!-- mapping a whole assembly -->
<mapping assembly="QuickStart" />

<!-- mappiong each mapping file -->
<mapping resource="NHibernate.Auction.Item.hbm.xml" assembly="NHibernate.Auction" />
<mapping resource="NHibernate.Auction.Bid.hbm.xml" assembly="NHibernate.Auction" />
</session-factory>

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Problem with mapping...
PostPosted: Fri Dec 18, 2009 6:29 am 
Newbie

Joined: Fri Dec 11, 2009 2:55 pm
Posts: 5
wolli wrote:
Ah, missed that in the first post:

ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();

is not enough. YOu have to somehow register the classes, either via the assembly (therefore you need "Embedded Resource") or each file on its own. You can do this in your code

http://nhforge.org/doc/nh/en/index.html#configuration-programmatic

or in the config file:
<session-factory>
... <!-- mapping a whole assembly -->
<mapping assembly="QuickStart" />

<!-- mappiong each mapping file -->
<mapping resource="NHibernate.Auction.Item.hbm.xml" assembly="NHibernate.Auction" />
<mapping resource="NHibernate.Auction.Bid.hbm.xml" assembly="NHibernate.Auction" />
</session-factory>

I just corrected my web.config file as you adviced me

Code:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
Server=(local)\SQLEXPRESS; Database=HibernateCollaborator; Integrated Security=true; Pooling=true
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
</property>
<property name="show_sql">
false
</property>
<mapping assembly="QuickStart" />
<mapping resource="HibernateCollaborator.Data.User.hbm.xml" assembly="HibernateCollaborator.Data" />
</session-factory>
</hibernate-configuration>


but throwed another exception Could not add assembly QuickStart


Top
 Profile  
 
 Post subject: Re: Problem with mapping...
PostPosted: Fri Dec 18, 2009 6:33 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
According to your mapping, your assembly would be "HibernateCollaborator.Core", wouldn't it ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Problem with mapping...
PostPosted: Fri Dec 18, 2009 12:22 pm 
Newbie

Joined: Fri Dec 11, 2009 2:55 pm
Posts: 5
wolli wrote:
According to your mapping, your assembly would be "HibernateCollaborator.Core", wouldn't it ?

OHH yes.. I corrected it, but there is same exception Could not add assembly QuickStart :(


Top
 Profile  
 
 Post subject: Re: Problem with mapping...
PostPosted: Fri Dec 18, 2009 12:28 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Are you sure that your config file was updated correctly ? Check your deployment directory or whereever your stuff goes. I'm not very familiar with web applications with Visual Studio.

If that's not the case, post your new config file and the code where you build the session factory.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Problem with mapping...
PostPosted: Fri Dec 18, 2009 12:52 pm 
Newbie

Joined: Fri Dec 11, 2009 2:55 pm
Posts: 5
wolli wrote:
Are you sure that your config file was updated correctly ? Check your deployment directory or whereever your stuff goes. I'm not very familiar with web applications with Visual Studio.

If that's not the case, post your new config file and the code where you build the session factory.

wolli can you write me your email, I'll send you this example, it is not big just simple example, I just take it to learn hibernate


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.