-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Is this design right?
PostPosted: Sat Jan 10, 2009 7:25 pm 
Newbie

Joined: Wed Jan 07, 2009 2:43 pm
Posts: 2
I don't really have an issue or anything but I'm just wondering if the way I'm using NHibernate is the correct way, conform with Nhibernate best practices.

To start off I'm very new to the framework, but I really like what the possibilities are.
I'm just creating something small to test all the things that are inside of the framework.

This is my setup:
I have 3 projects. Kinda like a 3Tier model
- Core: Which basically contains my entity classes. Customer, Order etc.
- Client: Which contains the forms that the user will see
- DataBaseLogic: Which contains the Nhibernate intelligence

Now I'll show some small code samples to let you see how I'm working. I don't want to start off implementing a bad design. So please if there are any remarkt, comments, articles. Please let me know.


Core
Core for instance contains a Customer class and a Nhibernate mapping file.

DatabaseLogic
Here is the project where the SessionFactory gets created and of course all the other database operations.

For now the creation of the SessionFactory is quite specific to the Customer class. It's a singleton class because this is a quite expensive process. I probably should have one class that creates the SessionFactory/database and just add all the other assemblies to it, right?
Here is the code for the SessionFactory

Then I created database opetation classes for each entity in the class the CRUD operations etc happen. Here is an example piece of code on getting a list of customers and deleting a customer. I know that I didn't implement a try/catch block. Mind the fact that this is just for testing purposes.

Client
Here are the forms that the user sees and on the button events, I call the appropreate methods from the DatabaseLogic layer. I know that is maybe better to implement a BusinessLogic layer, but I don't really have and business rules that need be checked on and I don't like the idea of an empty dispatching layer..so this is the reason it's not used for now.

The following pieces of code show how I retrieve a list of clients and how I add a new one from the client form.

Thank you for reading up to this part. If anyone thinks, why did he do this or that. Maybe he should do it better this way to gain better performance in this part..please..tell me.

Thanks again,

Kind regards,
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 3:31 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
Quote:
I probably should have one class that creates the SessionFactory/database and just add all the other assemblies to it, right?

Yes, you should design a service that handles the NH session stuff for you, imho. One method is an AbstractDAO that handles some of this. And there are other patterns as well. A good one to get started can be found here:

http://www.codeproject.com/KB/architect ... tices.aspx

This is a fairly complex sample, but it is also very nicely done.

-devon


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.