Thread:
 Quick Start did not work, what I did, to get it ru... 
 johannesbuchmann   25 Nov 2007, 10:12 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: johannesbuchmann (25 Nov 2007, 10:12) Replies: 0, Views: 1499
Subject: Quick Start did not work, what I did, to get it running
POST QUESTIONS ON THE FORUM! COMMENTS HERE SHOULD ADD VALUE TO THE PAGE!Hi,

I tried to follow this guide, but had some problems. 
VS 2005, NHibernate 1.2.0.400, MS-SQL 2005 ExpressEdition

I did the following to get it running: 
user-class:
    made all properties virtual

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

   <!-- Add this element -->
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
        <session-factory xmlns="urn:nhibernate-configuration-2.2">
            <property xmlns="urn:nhibernate-configuration-2.2"
name="hibernate.dialect">NHibernate.Dialect.MsSql2005Dialect</property>
            <property xmlns="urn:nhibernate-configuration-2.2"
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
            <property xmlns="urn:nhibernate-configuration-2.2"
name="connection.connection_string">Server=localhost\SQLEXPRESS;initial
catalog=[name of my db];Integrated Security=True</property>
            <mapping xmlns="urn:nhibernate-configuration-2.2"
assembly="NHibernate.Examples" />
        </session-factory>
    </hibernate-configuration>
</configuration>

client code:
Configuration cfg = new Configuration();
            // I added this:
            cfg.Configure();
            // instead of that: (Configure() seems to read all resources
anyway 
            // so AddAssembly() was trying to add the things twice)
            //cfg.AddAssembly("NHibernate.Examples");
            

            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.Password = "abc123";
            newUser.EmailAddress = "joe (at) cool (dot) com";
            newUser.LastLogon = DateTime.Now;

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

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

hope that makes sense and helps somehow
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]