-->
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: Help in App.config example
PostPosted: Mon Nov 12, 2007 12:43 pm 
Newbie

Joined: Sun Nov 04, 2007 6:05 am
Posts: 4
Hi
I am new at NHibernate and I read the “NHibernate Quick Start Guide” (http://www.hibernate.org/362.html)
I stopped at “Step 4: Creating a configuration file for your database”.

I want to take this example in win form code and not like web form like the example.
So, how I creating a configuration file for my database?
I get an error in
Quote:
“cannot open connection”

Thank for any help.
Ido


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 12, 2007 2:04 pm 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
Hi,

If you're using Visual Studio, add an Application Config File to the project from the list of installed templates to get an app.config file.

An example config section:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <!-- Add this element -->
  <configSections>
    <section
        name="hibernate-configuration"
        type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
        />
  </configSections>

  <!-- Add this element -->
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>

      <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
      <property name="connection.connection_string"> ... [your connection string] </property>

      <mapping assembly="AssemblyName" />
    </session-factory>
  </hibernate-configuration>


</configuration>


See http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/session-configuration.html, section 3.8 (XML Configuration File)


Top
 Profile  
 
 Post subject: Thanks it's work.....But....
PostPosted: Tue Nov 13, 2007 4:21 am 
Newbie

Joined: Sun Nov 04, 2007 6:05 am
Posts: 4
Thanks it's work.....But....
I have a little problem.
I get an error
Quote:
[NHibernate.MappingException] = {"Unknown entity class: NHibernate.User"}

When I try to run
Quote:
session.Save(newuser);

I will be grateful if you help me?
Thanks,
Ido

All Code
Code:
Configuration cfg = new Configuration();

cfg.AddAssembly("NHibernate");

ISessionFactory factory = cfg.BuildSessionFactory();

ISession session = factory.OpenSession();

ITransaction tran = session.BeginTransaction();

NHibernate.User newuser = new NHibernate.User();

newuser.Id = "joe_cool";

newuser.UserName = "Joseph Cool";

newuser.Password = "abc123";

newuser.EmailAddress = "joe@cool.com";

newuser.LastLogon = DateTime.Now;

session.Save(newuser);

tran.Commit();

session.Close();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 13, 2007 9:13 am 
Beginner
Beginner

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

I assume this error occurs due to the fact that NHibernate doesn't know the mapping file.
Try to fix it by embedding the User.hbm.xml file (right click on the file --> properties --> embedded....)

If it's not the problem. Write back and I'll try to figure out what's the problem.

Regards

_________________
dyahav


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.