The last couple of weeks I've been running around in circles, reading just about everything I been able to get my sweaty fingers on regarding NHibernate (and even alot of Hibernate docs as well)
I'm trying to create an application framework where I will be using NHibernate as the default mapper. I say default, because I really want it to be possible to shift or mapper (or dal implementation) without trouble. So...
My business objects, say User, has an interface for it's persisting and retrieving (just an example):
public interface IUser { User GetUser( Guid id ); void DeleteUser( User user ); IList GetAllUsers(); }
I then have a NHibernate implementation of this: UserMgrNH (but can make any implementation). My framework finds the correct data manager class from an xml configuration file. All this work as I want it to.
My problem lies in the LazyLoad mechanism in NHibernate. When loading an object, you do so through a Session object. When accessing a property (fx a collection of roles on my user object) it has to USE THE SAME SESSION. My problem lies in that because I've
abstracted my data access to manager classes I close the session every time. I really don't think that it's solution to just keep the session open, since it wraps an ADO connection to the database that should be closed.
All this could be solved if I just did a "manual" lazy load, ie making methods on my manager classes to load collections etc. But my next challenge is that I would like to use Paul Wilsons UI mapper to make simple administration modules in the framework.
The UI mapper ties together with any or mapper through an interface (that I've implemented to use with NHibernate). So if I bypass the lazy load in the mapper and make my own methods for retrieving fx roles for a user object, then the UI mapper cannot update
the roles since it's now out of NHibernates control.
So what does it boils down to....
I want to abstract my DAL using interfaces.
I want to use Paul Wilson's UI mapper
I would prefer to use NHibernate (but is this possible?!)
The Castle Framework actually has something for NHibernate that can do some of the stuff I'm after. But I really don't want a big framework (inside my own). Way too much configuration http://www.castleproject.org/castle/show/Facility-NHibernate
macrap
Participant
870 Points
174 Posts
NHibernate and servicelayer
Apr 28, 2005 08:03 AM|LINK
Hey all
The last couple of weeks I've been running around in circles, reading just about everything I been able to get my sweaty fingers on regarding NHibernate (and even alot of Hibernate docs as well)
I'm trying to create an application framework where I will be using NHibernate as the default mapper. I say default, because I really want it to be possible to shift or mapper (or dal implementation) without trouble. So...
My business objects, say User, has an interface for it's persisting and retrieving (just an example):
I then have a NHibernate implementation of this: UserMgrNH (but can make any implementation). My framework finds the correct data manager class from an xml configuration file. All this work as I want it to.
My problem lies in the LazyLoad mechanism in NHibernate. When loading an object, you do so through a Session object. When accessing a property (fx a collection of roles on my user object) it has to USE THE SAME SESSION. My problem lies in that because I've abstracted my data access to manager classes I close the session every time. I really don't think that it's solution to just keep the session open, since it wraps an ADO connection to the database that should be closed.
All this could be solved if I just did a "manual" lazy load, ie making methods on my manager classes to load collections etc. But my next challenge is that I would like to use Paul Wilsons UI mapper to make simple administration modules in the framework. The UI mapper ties together with any or mapper through an interface (that I've implemented to use with NHibernate). So if I bypass the lazy load in the mapper and make my own methods for retrieving fx roles for a user object, then the UI mapper cannot update the roles since it's now out of NHibernates control.
So what does it boils down to....
I want to abstract my DAL using interfaces.
I want to use Paul Wilson's UI mapper
I would prefer to use NHibernate (but is this possible?!)
References
I want to achieve this (abstracted DAL):
http://www.theserverside.net/articles/showarticle.tss?id=NHibernate
More: http://www.theserverside.net/articles/showarticle.tss?id=NHibernateP2
Also here: http://www.codeproject.com/dotnet/nhibernatept1.asp
The Castle Framework actually has something for NHibernate that can do some of the stuff I'm after. But I really don't want a big framework (inside my own). Way too much configuration
http://www.castleproject.org/castle/show/Facility-NHibernate
Best regards
Rasmus
Sane Productions
- Because it's too easy being insane
www.sane.dk