-->
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.  [ 6 posts ] 
Author Message
 Post subject: Accessing other objects in the domain without the session
PostPosted: Tue Dec 27, 2005 11:05 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
I have followed the practice of keeping my domain layer completely unaware of the persistence engine and the objects are therefore unable to see the NHibernate session.

The problem I have is that I want to be able to access some other objects in the domain that I am not able to navigate to via the object hierarchy.

What is the recommended approach for solving this problem?

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 7:45 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It depends on the kind of application you are developing (ASP.NET or WinForms). ASP.NET approach is detailed in the docs (you can even use Hibernate docs, the web stuff is conceptually similar), WinForms are more complicated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 4:09 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
This is an interesting situation ... we haven't gotten to it yet ourselves, but as you describe it, I'm sure we will soon. We have already faced something similar though -- the need for code in the domain layer to create new entities, which may be subclassed (using the same class name but different namespace).

What we've done is to create an EntityServices singleton, which has an EntityFactory and EntityGateway that can be set during EntityServices' initialization (otherwise default implementations are used). The domain layer can know about EntityServices.Factory and EntityServices.Gateway, but does not know about NHibernate. The gateway may provide entities from a source other than NHibernate, and may understand queries of types other than HQL. No NHibernate types are exposed in the public API of EntityServices, EntityFactory or EntityGateway.

We will probably go a step further and define "named queries" of a sort. EntityServices (or EntityGateway) will have a registry of queries, where each query knows its "type" -- NHibernate or whatever else. Then any code executing queries simply requests them by name and parameters -- e.g.

Code:
myResultSet = EntityServices.Gateway.ExecuteQuery(someQueryName, someQueryParameters);


and has no idea if NHibernate (or any persistence layer) is being used to provide the results. These queries could be executed from within the domain layer itself, without the problems of high coupling.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 5:34 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi Sergey,

I have spent quite a lot of time poking aroung in the docs and the forum but was unable to find an answer to this specific question. Can you please advise which doc contains information about this problem?

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 29, 2005 6:17 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi Nels,

Thanks for the response.

I have only hit this need in one special case within the domain although I can imagine other places where it might also be required.

I have already created a service layer that the UI calls to interact with the domain and this provides methods for CRUD and searching of objects. The domain is obviously unaware of this service layer and would not be able to use it anyway as it requires a session to be passed in on the constructor and we don't have that in the domain.

However, I guess what you are proposing is another form of service layer that the domain can use. I am a bit unsure about how it knows how to create the session though as it needs to know what the database connection is and this comes from the UI configuration file. How do you handle this?

Cheers,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 12:39 am 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Our gateway that internally performs NHibernate operations gets the database connection info from hibernate.cfg.xml (or web.config if used with ASP.NET). NHibernate gets it for us, actually, when an instance of NHibernate.Cfg.Configuration is is created. We have a static method on our EntityServices singleton called Start() that the application needs to call to initialize stuff (it creates an NHibernate configuration object, adds domain assemblies to it, creates a SessionFactory, etc), but no parameters need to be passed to this Start() method.


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