Click here to Skip to main content
15,884,176 members
Articles / Programming Languages / SQL

NHibernate Made Simple

Rate me:
Please Sign up or sign in to vote.
4.92/5 (207 votes)
31 Oct 2007CPOL44 min read 776.5K   23K   527  
A simple, straightforward tutorial that will get you up to speed on the fundamentals of NHibernate as quickly as possible
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

    <!-- Configuration Sections In This File -->
    <configSections>

        <!-- NHibernate Section -->
        <section 
            name="hibernate-configuration" 
            type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate"
        />

        <!-- Log4Net Section -->
        <section
            name="log4net"
            type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
        />

    </configSections>

    <!-- NHibernate Configuration -->
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
        <session-factory>
            <property name="connection.provider">
                NHibernate.Connection.DriverConnectionProvider
            </property>
            <property name="dialect">
                NHibernate.Dialect.MsSql2005Dialect
            </property>
            <property name="connection.driver_class">
                NHibernate.Driver.SqlClientDriver
            </property>
            <property name="connection.connection_string">
                    Data Source=(local)\SQLExpress;Initial Catalog=NHibernateSimpleDemo;Integrated Security=True;Pooling=False
            </property>
        </session-factory>
    </hibernate-configuration>


    <!-- Log4Net Configuration -->
    <log4net>

        <!-- Define an output appender (where the logs can go) -->
        <appender name="LogFileAppender" type="log4net.Appender.FileAppender, log4net">
            <param name="File" value="log.txt" />
            <param name="AppendToFile" value="true" />
            <layout type="log4net.Layout.PatternLayout, log4net">
                <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
            </layout>
        </appender>

        <!-- Note: Priority level can be ALL/DEBUG/INFO/WARN/ERROR/FATAL/OFF -->
        <!-- Setup the root category, set the default priority level and add the appender(s) (where the logs will go) -->
        <root>
            <priority value="WARN" />
            <appender-ref ref="LogFileAppender" />
        </root>
    </log4net>

</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Foresight Systems
United States United States
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.

Comments and Discussions