Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Getting Started with NHibernate: Part II

    While writing the code necessary for this installment, I found myself falling prey to feature-creep.  So I've decided to keep it fairly simple in the beginning.  However, once the basic components are working I'll start introducing more features.  I thought this might be a good way to demonstrate what is and isn't required to add new functionality to a working NHibernate application.

    The application's initial functionality will consist of blog users being able to post new blog posts, comment on posts,  and reply to other comments.  Only users with the correct role membership will be able to post, all users will be able to comment and reply to comments.  Also, the comments should be threaded so conversations can be followed more easily.

    The domain model has just 4 classes (for now):


 NHBlog UML diagram



    The Sql Express 2005 database will have 5 tables persisting our 4 classes.  The extra database table UserRole will persist the many-to-many relationship between BlogUser and BlogRole. 


NHBlog database diagram


    Also notice that the "Depth" property in the Comment class is not actually persisted, it is a read-only value that is generated when a collection of comments for a BlogPost is loaded and represents the level of the comment in the comment hierarchy (threaded convesations!).  See the attachment for the database script.

    In Part III we will create the mapping glue that binds the model and database together.

Posted 05-22-2007 8:26 PM by anortham
Filed under: ,



Derik Whittaker wrote re: Getting Started with NHibernate: Part II
on 05-24-2007 7:28 AM


Maybe i was doing something wrong but I had trouble getting the DB script to run correctly.  I had to remove the following line in order to get it to build the tables correctly.


Not 100% sure why this was not working, but I removed it and all was better.

Thanks for these posts, I look forward to playing around with this code to learn NHibernate.


anortham wrote re: Getting Started with NHibernate: Part II
on 05-24-2007 9:31 AM


Sorry about the trouble, after the next article I'll attach the code and database to the article to make it a little easier to get up and running quickly.  That's the nice thing about SQL Express.

Chris May wrote NHibernate Tutorials
on 09-16-2008 3:17 PM
Swarup wrote re: Getting Started with NHibernate: Part II
on 11-07-2008 9:21 AM

I was wondering if the part 3 and 4 are out. It would definitely help in learning Hibernate

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)