Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 745509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:35:29+00:00 2026-05-14T09:35:29+00:00

I tried an example from NHibernate in Action book and when I try to

  • 0

I tried an example from NHibernate in Action book and when I try to run the app, it throws an exception saying “Could not compile the mapping document:

HelloNHibernate.Employee.hbm.xml”

Below is my code,

Employee.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="HelloNHibernate.Employee, HelloNHibernate" lazy="false" table="Employee">
<id name="id" access="field">
  <generator class="native"/>
</id>
<property name="name" access="field" column="name"/>
<many-to-one access="field" name="manager" column="manager" cascade="all"/>
</class>
</hibernate-mapping>

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using System.Reflection;
using NHibernate.Cfg;

namespace HelloNHibernate
{
class Program
{
    static void Main(string[] args)
    {
        CreateEmployeeAndSaveToDatabase();
        UpdateTobinAndAssignPierreHenriAsManager();
        LoadEmployeesFromDatabase();

        Console.WriteLine("Press any key to exit...");
        Console.ReadKey();
    }

    static void CreateEmployeeAndSaveToDatabase()
    {
        Employee tobin = new Employee();
        tobin.name = "Tobin Harris";

        using (ISession session = OpenSession())
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(tobin);
                transaction.Commit();
            }
            Console.WriteLine("Saved Tobin to the database");
        }
    }

    static ISession OpenSession()
    {
        if (factory == null)
        {
            Configuration c = new Configuration();
            c.AddAssembly(Assembly.GetCallingAssembly());
            factory = c.BuildSessionFactory();
        }
        return factory.OpenSession();
    }

    static void LoadEmployeesFromDatabase()
    {
        using (ISession session = OpenSession())
        {
            IQuery query = session.CreateQuery("from Employee as emp order by emp.name asc");

            IList<Employee> foundEmployees = query.List<Employee>();

            Console.WriteLine("\n{0} employees found:", foundEmployees.Count);

            foreach (Employee employee in foundEmployees)
                Console.WriteLine(employee.SayHello());
        }
    }

    static void UpdateTobinAndAssignPierreHenriAsManager()
    {
        using (ISession session = OpenSession())
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                IQuery q = session.CreateQuery("from Employee where name='Tobin Harris'");

                Employee tobin = q.List<Employee>()[0];
                tobin.name = "Tobin David Harris";

                Employee pierreHenri = new Employee();
                pierreHenri.name = "Pierre Henri Kuate";

                tobin.manager = pierreHenri;
                transaction.Commit();

                Console.WriteLine("Updated Tobin and added Pierre Henri");
            }
        }
    }

    static ISessionFactory factory;
}
}

Employee.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloNHibernate
{
class Employee
{
    public int id;
    public string name;
    public Employee manager;

    public string SayHello()
    {
        return string.Format("'Hello World!', said {0}.", name);
    }
}
}

App.config

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0, Culture=neutral
             PublicKeyToken=b77a5c561934e089"/>
  </configSections>
  <nhibernate>
    <add key="hibernate.show_sql" value="false"/>
    <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
    <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
    <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
    <add key="hibernate.connection.connection_string" value="Server=(local)\SQLEXPRESS; Database=HelloNHibernate;Integrated Security=SSPI;"/>
  </nhibernate>
</configuration>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T09:35:29+00:00Added an answer on May 14, 2026 at 9:35 am

    Let’s open the Matryoshka doll a bit further, and solve the other problem:

    In this line:

    <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0, Culture=neutral
    PublicKeyToken=b77a5c561934e089"/>

    you’re missing a comma between “neutral” and “PublicKeyToken”.

    Give that a try.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Coming from NHibernate, I've tried to do something like this in Java (first example):
I tried to compile the example posted ( C++ Service Providers ) and failed
I was browsing through Text Processing in Python and tried its example about Schwartzian
I have read an example and tried to duplicate it's methods but with weird
I have tried using the obvious method as outlined in the following example but
Tried to map it from Preferences -> Settings -> Keyboard, but the key combo
Tried something like this: HttpApplication app = s as HttpApplication; //s is sender of
I am trying a very simple Fluent Nhibernate example: SQL 2005 database with one
I have tried different examples to filter a gridview by dropdownlist, but is it
I need to upload images using FileUpload without postback(using Ajax).I tried many examples.But in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.