Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Alan Northam



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.


Published May 22 2007, 08:26 PM by anortham
Filed under: ,
Attachment: NHBlogDBScript.zip

Comments

Derik Whittaker said:

Alan,

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.

WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

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.

Derik

# May 24, 2007 7:28 AM

anortham said:

Derik,

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.

# May 24, 2007 9:31 AM

Chris May said:

# September 16, 2008 3:17 PM

Swarup said:

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

# November 7, 2008 9:21 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors

Proudly Partnered With