Multi server configuration

2 views
Skip to first unread message

Sheraz

unread,
Mar 31, 2008, 8:26:00 PM3/31/08
to nhusers
Hello,
We are in the middle of deciding if we can use NHibernate.
We want to be able to have our business layer and data Access layer
deployed on a seperate server. So we want our client to interact with
these layers that are physically on a seperate server. Does NHibernate
have any issues when the layers are deployed on seperate physical
servers. Also how do we need to configre NHibernate in this case.
Thanks a million

Ayende Rahien

unread,
Mar 31, 2008, 9:34:06 PM3/31/08
to nhu...@googlegroups.com
I can't figure out this question, what do you mean data layer and business layer on separate machines?

Ben Scheirman

unread,
Mar 31, 2008, 10:03:40 PM3/31/08
to nhu...@googlegroups.com
You can do this as your classes do not have to inherit from anything.
It does limit you from taking full advantage of lazy loading and the
session level cache.

Just search around on this. There are quiteca few resources talking
about this.

Sent from my iPhone

Fabio Maulo

unread,
Apr 1, 2008, 12:39:50 AM4/1/08
to nhu...@googlegroups.com
We have few experience in a physical multi-tiers application using NH.... but somebody have it since NH1.0.4.
Hope he appear in this forum...

Bye.
Fabio Maulo.

Sheraz

unread,
Apr 1, 2008, 12:38:14 AM4/1/08
to nhusers
@Ayende: I meant to say seperating the layers physically. Having a
seperate server that would have the business and dataaccess layer and
all the Business/DataLayer work will be executed on that server (I
really don't know why the company wants to go this way. Infact why
would someone want to go with this infrastructure becasue we don't
have hundreds of requests or heavy work load for this app. Can you put
some light on it as to when it's better to have a seperate machine to
execute business and data access logic).


@Ben: I did do the search but couldn't really findout anything useful.
Could you direct me to a link and i'd be great if they have a code
example. What I read so far is that you'd need 2nd level cache which
means using Nchace (not a free framework). Also that i'd require
either using remoting or web service to make calls from front end to
interact with Business/DataLayer since they are not in the same App
Domain.

Thanks
On Mar 31, 9:03 pm, Ben Scheirman <subdigi...@gmail.com> wrote:
> You can do this as your classes do not have to inherit from anything.  
> It does limit you from taking full advantage of lazy loading and the  
> session level cache.
>
> Just search around on this. There are quiteca few resources talking  
> about this.
>
> Sent from my iPhone
>
> On Mar 31, 2008, at 7:26 PM, Sheraz <sher...@gmail.com> wrote:
>
>
>
>
>
> > Hello,
> >          We are in the middle of deciding if we can use NHibernate.
> > We want to be able to have our business layer and data Access layer
> > deployed on a seperate server. So we want our client to interact with
> > these layers that are physically on a seperate server. Does NHibernate
> > have any issues when the layers are deployed on seperate physical
> > servers. Also how do we need to configre NHibernate in this case.
> > Thanks a million- Hide quoted text -
>
> - Show quoted text -

Ayende Rahien

unread,
Apr 1, 2008, 7:45:02 AM4/1/08
to nhu...@googlegroups.com
Sheraz,
This is a common requirement in situations where high scalability is required. You want to have an App Server machine so you can put several web servers machine to distribute the load.
NH definitely supports this scenario. It means that it is used internally in the App Server, and the web server tends to get DTO back.
I recommend taking a look at my "Going Distributed" screen cast, which talks about the challenges in this environment, and taking NServiceBus for a long spin.
Message has been deleted

Tommaso Caldarola

unread,
Apr 1, 2008, 8:09:12 AM4/1/08
to nhusers
Hi people,

on Fabio Maulo suggestion I'm joining ths group.

Well, I'm involved in a 3-tier architecture project, with
DB server, application server (hosted on windows service) and client
(windows forms).
The communicatin protocol is managed via remoting.

First of all, you cannot configure NH for this scenario; NH is an ORM
and so does not
know anything about logic or separate layers.

In my project (NH 1.0.4) an entity (got via NH) is an object marked as
MarshalByValue, the application
server dispatches the MBV's on client request.
Moreover, you can still have the lazy-loading, the implementation of a
property one-to-many could be:

public virtual OrderCollection Orders
{
get
{
if(//check if initialized (triggers a round-trip on
server))
{
m_Orders =
Proxy.LazyLoadCollection<OrderCollection>(this, //....);
}
return m_Orders;
}
}

where Proxy is the gateway to the application server. The
LazyLoadCollection method sends the request (the current item and type
of child collection) and back-end side the repository loads the items
and then attach they to the parent item, a simple implementation could
be the following:

NHibernate.Collection.PersistentCollection pColl;
try
{
openSession();

if (!pColl.WasInitialized)
{
if (//item is dirty)
{
_session.Update(item);
}
else
{
_session.Lock(item, LockMode.None);
}

NHibernateUtil.Initialize(pColl);
}
}
catch()
{
//here you could get and manage some exceptions; if
item has a stalestateobject, it's an old object, and so on...
}
finaly
{
closeSession();
}

In this way, I can manage several scenario as such as off-line, 3-
tier, stand-alone without make any change switching on proxy.

I hope this helps you.

Tommaso

Ayende Rahien

unread,
Apr 1, 2008, 8:22:08 AM4/1/08
to nhu...@googlegroups.com
Trying to do lazy loading across tiers is a bad idea.
I would recommend going with message passing and DTO here.

Tommaso Caldarola

unread,
Apr 1, 2008, 8:29:24 AM4/1/08
to nhusers
Theorically yes, of course, but we have scenario where I cannot pass
the entire DTO because it is very "heavy"; a decision support system
with drill-down funcionality is very hard to code without lazy loading
because you do not know the next step the User is going to do.

Fabio Maulo

unread,
Apr 1, 2008, 9:34:26 AM4/1/08
to nhu...@googlegroups.com
Thanks Tommaso to share your experience.
Take a look to NH2.0.0, there is a new configurable ProxyFactoryFactory.
An example on how use it, for a different matter, is here
http://blechie.com/WPierce/archive/2008/02/17/Lazy-Loading-with-nHibernate-Under-Medium-Trust.aspx

I think that, perhaps, you can simplify your implementation using custom proxy engine.

Bye.
Fabio Maulo

Luis Abreu

unread,
Apr 1, 2008, 10:59:08 AM4/1/08
to nhu...@googlegroups.com
Hello.

I've been working with win forms + wcf services + nhibernate for
implementing our repositories. We're not using lazy loading but we're using
a lot of dto, specially for showing lists of items. After running some
tests, it seemed like this is the best approach for just sending the
necessary info down the wire, without loading lots of unnecessary objects.

--
Regards,
Luis Abreu
email: labreu_at_gmail.com
PT Blog: http://weblogs.pontonetpt.com/luisabreu
EN Blog:http://msmvps.com/blogs/luisabreu/default.aspx
http://www.pontonetpt.com
MVP profile: http://mvp.support.microsoft.com/profile/luis.abreu

Ben Scheirman

unread,
Apr 1, 2008, 1:50:55 PM4/1/08
to nhu...@googlegroups.com
@Ben: I did do the search but couldn't really findout anything useful.
Could you direct me to a link and i'd be great if they have a code
example. What I read so far is that you'd need 2nd level cache which
means using Nchace (not a free framework). Also that i'd require
either using remoting or web service to make calls from front end to
interact with Business/DataLayer since they are not in the same App
Domain.


To use the 2nd level cache you just have to pick a provider.  Some are free, just read up on the docs.  And I'd suggest to avoid remoting and web services and leverage WCF instead.  Much cleaner experience, and you have the flexibility to expose/consume whatever format & protocol you want.

Definitely read up on Udi Dahan's blog (http://udidahan.weblogs.us/) as he mentions using NHibernate in a messaging scenario where your entities are all server side.

Look into projection and Data Transfer Objects as well.  It can make your interfaces less chatty and more appropriate for your app.

Sheraz

unread,
Apr 1, 2008, 11:52:02 AM4/1/08
to nhusers
@Luis Abreu: can you you share the code with users here. a small
sample would help alot
@Ayende: I see that in distributed environment, using lazy loading is
a killer and give a lot of trouble. I came across this
http://codeclimber.blogspot.com/2008/01/remote-nhibernate-5-lessons-learned.html
It's worth reading it. Do you think that all the issues discussed in
above link and the solutinos are right or you have a better idea?????

On Apr 1, 10:59 am, "Luis Abreu" <lab...@gmail.com> wrote:
> Hello.
>
> I've been working with win forms + wcf services + nhibernate for
> implementing our repositories. We're not using lazy loading but we're using
> a lot of dto, specially for showing lists of items. After running some
> tests, it seemed like this is the best approach for just sending the
> necessary info down the wire, without loading lots of unnecessary objects.
>
> --
> Regards,
> Luis Abreu
> email: labreu_at_gmail.com
> PT Blog:http://weblogs.pontonetpt.com/luisabreu
> EN Blog:http://msmvps.com/blogs/luisabreu/default.aspxhttp://www.pontonetpt.com

Sheraz

unread,
Apr 1, 2008, 1:37:17 PM4/1/08
to nhusers
@Ayende: Have a look at this "http://codeclimber.blogspot.com/2008/01/
remote-nhibernate-5-lessons-learned.html". He talks about issues
related to nHibernate sesion with lazy fetching. So if I go with
message passing with DTO, I woudln't come across these issues???

@Luis: You load an object eagerly (Order with LineItems), close the
session, populate DTO(s) and send them using wcf (we are still on 2.0
so I'm assuming remoting won't many any difference), the cliet makes
changes, sends the dtos back to server. Servr maps the dto back to
actual object. Now since the session is closed, you update the whole
object graph. Is this all correct?

On Apr 1, 10:59 am, "Luis Abreu" <lab...@gmail.com> wrote:
> Hello.
>
> I've been working with win forms + wcf services + nhibernate for
> implementing our repositories. We're not using lazy loading but we're using
> a lot of dto, specially for showing lists of items. After running some
> tests, it seemed like this is the best approach for just sending the
> necessary info down the wire, without loading lots of unnecessary objects.
>
> --
> Regards,
> Luis Abreu
> email: labreu_at_gmail.com
> PT Blog:http://weblogs.pontonetpt.com/luisabreu
> EN Blog:http://msmvps.com/blogs/luisabreu/default.aspxhttp://www.pontonetpt.com

Ayende Rahien

unread,
Apr 1, 2008, 3:03:02 PM4/1/08
to nhu...@googlegroups.com
Take a look at my recent webcast about going distributed.
Trying to do lazy loading across several tiers is a problem.
It is easier to request the info at one go.

Sheraz

unread,
Apr 1, 2008, 3:36:29 PM4/1/08
to nhusers
@Ayende: will do but is the solution equally applicable using remoting
since we are on 2.0

On Apr 1, 3:03 pm, "Ayende Rahien" <aye...@ayende.com> wrote:
> Take a look at my recent webcast about going distributed.
> Trying to do lazy loading across several tiers is a problem.
> It is easier to request the info at one go.
>
>
>
> On Tue, Apr 1, 2008 at 8:37 PM, Sheraz <sher...@gmail.com> wrote:
>
> > @Ayende: Have a look at this "http://codeclimber.blogspot.com/2008/01/
> > remote-nhibernate-5-lessons-learned.html<http://codeclimber.blogspot.com/2008/01/remote-nhibernate-5-lessons-l...>".
> > > - Show quoted text -- Hide quoted text -

Ayende Rahien

unread,
Apr 1, 2008, 3:38:56 PM4/1/08
to nhu...@googlegroups.com
Yes.

Luis Abreu

unread,
Apr 1, 2008, 3:48:35 PM4/1/08
to nhu...@googlegroups.com

>@Luis: You load an object eagerly (Order with LineItems), close the
>session, populate DTO(s) and send them using wcf (we are still on 2.0
>so I'm assuming remoting won't many any difference), the cliet makes
>changes, sends the dtos back to server. Servr maps the dto back to
>actual object. Now since the session is closed, you update the whole
>object graph. Is this all correct?
>
Not in that example. If I'm loading an order, then I load all the lineitems.
On the other hand, if I'm showing a list of orders, then I will only return
a DTO because in most cases you'll only need a small subset of the info you
have in an order.

Btw, do notice that when I return a DTO I'm not loading the Order+LineItems.
I'm using NHibernate to make a projection over those elements (NH does this
really well since it will end up writing the SQL that returns only the
needed values). You can get more info on this by searching for Nhibernate
projections on the web.

Luis

Reply all
Reply to author
Forward
0 new messages