-->
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.  [ 4 posts ] 
Author Message
 Post subject: Architecture question - singleton, base classes & hibern
PostPosted: Tue Oct 18, 2005 10:57 am 
In terms of using nHibernate in a real world application, can somebody provide an opinion on the following:

1. Creating a singleton for the session factory and getting an instance to open sessions. Are there any problems with this approach?

2. Creating a base class which knows how to save, load, delete to abstract nHibernate from business objects in order to facilitate a swap of ORM down the track.


Top
  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 8:47 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
1- No problem.

2- That's a possible solution... You may also implement a Gateway.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: gateway
PostPosted: Wed Oct 19, 2005 9:15 pm 
Hi KPixel,

Thanks for the response.

Can you elaborate on what you mean by Gateway? Or point me to the correct resources?

Thanks


Top
  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 10:32 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
Fowler defines "Gateway" as "an object that encapsulates access to an external system or resource". You might look at implementing a "Table Data Gateway" to encapsulate your NH calls. This kind of structure is very tightly bound to your relational model however, which tends to work less effectively as the complexity of your domain model increases. My preference is use the "Repository" design pattern, which is more aligned with the domain model.

So you would have a Repository class for each persistent class in your domain layer (e.g. CustomerRepository, OrderRepository, etc...). Then you would place methods on each repository class that perform the relevant persistence operations for the associated domain class. So for example, you might have CustomerRepository.SaveCustomer(...) or CustomerRepository.FindByName(...).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.