Thanks for not taking my frustration personally. I will try to find
time to revisit the caching issue later. The session connection was
really the point of the chain and I think I have the answer I need,
even if not the one I want. Sometimes the curve feels more like a
cliff but more effort to post questions to the community might be the
answer there so I will move on.

Thanks again.

On Feb 12, 12:08 pm, Diego Mijelshon <[email protected]> wrote:
> I won't "overrule" Oren's answer :-), but in NH 2.x Linq is built on top of
> the Criteria API, and it supports caching....
>
> read more »
>
> Google "effectus nhibernate" and "chinook nhibernate" and you'll get the
> relevant results at the top (don't make me use lmgtfy)
>
> I don't think NH is hard to use at all, but it does have a learning curve.
> Fortunately, there are lots of examples, documentation (not the best in the
> world, but it's ok) and this great community that's always willing to help
> in the forums, stackoverflow, and the blogs of Fabio, Oren, José and others.
>
>    Diego
>
>
>
> On Fri, Feb 12, 2010 at 11:38, CSLem <[email protected]> wrote:
> > So, this is where I get confused. Much of the info published in
> > various sites on the web and even in this forum conflict. I initially
> > set my app up using straight NHibernate and was using (or abusing?)
> > the cache trying to implement some of my requirements. When
> > Linq2NHibernate was released I moved to that because it seemed the
> > queries would be easier for others who are even less familiar with
> > NHibernate to maintain since they are already using Linq. The cache
> > was not performing as I had expected after that so I sent a question
> > to Oren who said the cache was not available in Linq2NH. Putting
> > costly queries into the cache does not appear to be an option for me.
> > And even the Linq2NH appears to do odd things since a simple lambda
> > appears to grab the entire list and filter rather than passing the
> > filter to SQL. I have yet to even tackle tracking that down.
>
> > I guess my point is that there are so many ways to approach a given
> > problem it is very easy to be sidetracked with a single statement that
> > heads you off in the wrong direction for your specific project.
>
> > On that note...trying googling Effectus and Chinook and you will see
> > why it can be hard to find pertinent information.
>
> > I don't mean this as a grouse...just venting frustration over trying
> > to use what appears to be a good tool to implement some ugly
> > requirements and finding it very difficult to plow through.
>
> > On Feb 12, 8:15 am, Diego Mijelshon <[email protected]> wrote:
> > > John,...
>
> > > read more »
>
> > > Yes, it's a NH session per web request.
> > > Storing NHibernate sessions in ASP.NET sessions is a terrible, terrible
> > > idea.
> > > Why would you want to "hold data in session" across web requests?? That
> > > basically kills your scalability.
> > > If you are concerned about costly queries, that's what the 2nd level
> > cache
> > > is for.
>
> > >    Diego
>
> > > On Fri, Feb 12, 2010 at 10:05, John Davidson <[email protected]>
> > wrote:
> > > > Diego
>
> > > > You say web app pattern is NHibernate session per request. Is that each
> > > > page request?
>
> > > > Or do you mean that web pattern should be NHibernate session per User
> > web
> > > > session?
>
> > > > The latter allows NHibernate to effectively hold data in session across
> > web
> > > > requests, and only has an additional cost when the web session is
> > abandoned
> > > > by the user without the apps knowledge, though the session will expire
> > after
> > > > 20 minutes(defualt).
>
> > > > John Davidson
>
> > > > On Thu, Feb 11, 2010 at 7:59 PM, Diego Mijelshon <
> > [email protected]>wrote:
>
> > > >> In a web app, the usual pattern is session per request.
>
> > > >> You should research existing samples with patterns for web and desktop
> > > >> apps (which are very different) before reinventing the wheel and
> > investing
> > > >> in an architecture that will bite you later.
> > > >> Just sayin'.
>
> > > >> For desktop, two interesting approaches are Effectus and Chinook.
>
> > > >>    Diego
>
> > > >> On Thu, Feb 11, 2010 at 21:35, CSLem <[email protected]> wrote:
>
> > > >>> The logic I create here will certainly be used later in a web version
> > > >>> of this application. Keeping the session to a minimum will be
> > > >>> essential there. I am really trying to implement a Session per
> > > >>> Conversation sort of model with that web future in mind and was
> > hoping
> > > >>> to keep the session strictly in the data layer. If I use a long-
> > > >>> running session the UI will have to be able to open and close the
> > > >>> session.
>
> > > >>> If I open a session and begin a transaction, then disconnect (as
> > > >>> opposed to closing and disposing) don't all the objects stay in the
> > > >>> session? As I recall, I had some issues in the first attempt at this
> > > >>> application because there were times when I wanted what was in the DB
> > > >>> - not what was cached in the session - and I could not force NHIb to
> > > >>> do that. For example, if I get a list of objects that is strictly for
> > > >>> searching, then want to update a single object in the database I need
> > > >>> to Get the object from the database at that time (to help eliminate
> > > >>> StaleObjectStateExceptions) and give that to the presentation layer -
> > > >>> not the object that was initially retrieved in the list.
>
> > > >>> On Feb 11, 5:26 pm, Diego Mijelshon <[email protected]> wrote:
> > > >>> > Why do you try to avoid a "long running session"?
> > > >>> > A session does not keep a DB connection open until you begin a
> > > >>> transaction.
>
> > > >>> >    Diego
>
> > > >>> > On Thu, Feb 11, 2010 at 19:33, CSLem <[email protected]>
> > wrote:
> > > >>> > > But the session is closed between the Get and the commit since I
> > am
> > > >>> > > trying to avoid the long running session. That is I Get the
> > object,
> > > >>> > > close the session and hand the object to the presentation layer.
> > At
> > > >>> > > some point the object is passed back to the data layer.
>
> > > >>> > > As a result I have a detached object and need to open a new
> > session
> > > >>> > > and attach the object to the new session that I have. Doesn't
> > that
> > > >>> > > mean I have to call some save method or lock? I have tried lock
> > and,
> > > >>> > > if the collections have been retrieved, I get a "dirty
> > collection"
> > > >>> > > error.
>
> > > >>> > > On Feb 11, 4:22 pm, Jason Meckley <[email protected]>
> > wrote:
> > > >>> > > > if the parent is managing the child entity and the parent is
> > > >>> retrieved
> > > >>> > > > from the database there is no reason to explicitly call any of
> > the
> > > >>> > > > Save operations. NH will do this for you. example
>
> > > >>> > > > var id = 1;
> > > >>> > > > var nameOfChild = "Jason";
> > > >>> > > > using(var tx = session.BeginTransaction())
> > > >>> > > > {
> > > >>> > > >      try
> > > >>> > > >      {
> > > >>> > > >           var parent = session.Get<Parent>(id);
> > > >>> > > >           parent.Add(nameOfChild);
> > > >>> > > >           tx.Commit();
> > > >>> > > >      }
> > > >>> > > >      catch
> > > >>> > > >      {
> > > >>> > > >          tx.Rollback();
> > > >>> > > >          throw;
> > > >>> > > >      }
>
> > > >>> > > > }
>
> > > >>> > > > where parent.Add looks like
> > > >>> > > > class Parent
> > > >>> > > > {
> > > >>> > > >     private IList<Child>() children = new List<Child>();
>
> > > >>> > > >     public virtual void Add(string name)
> > > >>> > > >     {
> > > >>> > > >         var child = new Child{Name = name, Parent = this};
> > > >>> > > >         children.Add(child);
> > > >>> > > >     }
>
> > > >>> > > > }
>
> > > >>> > > > On Feb 11, 4:59 pm, CSLem <[email protected]> wrote:
>
> > > >>> > > > > Sorry for the long delay. I am still struggling to get the
> > maps
> > > >>> > > > > correct and SQL performing as I need.
>
> > > >>> > > > > I do add the child to the list. Right now, after some changes
> > to
> > > >>> > > > > cascade options and logic I have the tests doing all three
> > > >>> operations.
> > > >>> > > > > However, it only works in a long running session.
>
> > > >>> > > > > My simple view of the app is this:
> > > >>> > > > > 1) Get an object from the data layer. This starts with Parent
> > so
> > > >>> the
> > > >>> > > > > first object I get is the parent with no lazy collections
> > loaded.
> > > >>> > > > > 2) Close the session
> > > >>> > > > > 3) Let the user do whatever with the parent object
> > > >>> > > > > 4) IF the user needs the collection or collections, open a
> > new
> > > >>> > > > > session, retrieve the collections, close the session
> > > >>> > > > > 5) Let the user make necessary changes to Parent and Children
> > > >>> > > > > 6) When the user indicates they want to save open a new
> > session,
> > > >>> call
> > > >>> > > > > session.SaveOrUpdate(parent) and have the data layer cascade
> > > >>> whatever
> > > >>> > > > > is changed.
>
> > > >>> > > > > I would assume this is how an httpsession is handled. I am
> > not in
> > > >>> a
> > > >>> > > > > web session but still don't want the session to remain open
> > since
> > > >>> the
> > > >>> > > > > users often open the application and leave it up all day,
> > > >>> creating a
> > > >>> > > > > very long connection if I don't destroy the session after
> > each
> > > >>> action.
>
> > > >>> > > > > If I close the session after I get the object(s) then when I
> > pass
> > > >>> the
> > > >>> > > > > Parent back to the data layer and call SaveOrUpdate(parent)
> > > >>> NHibernate
> > > >>> > > > > issues an UPDATE statement for every object in the graph -
> > Parent
> > > >>> and
> > > >>> > > > > EVERY child that has been retrieved. I have tried used
> > > >>> > > > > SaveOrUpdateCopy instead but then seem to have problems in my
> > > >>> unit
> > > >>> > > > > test if I attempt to update the object twice. That is, get
> > the
> > > >>> Parent
> > > >>> > > > > and Children, update something on one of the Children, send
> > it
> > > >>> back to
> > > >>> > > > > the database. Update something on the Parent, send it back to
> > the
> > > >>> > > > > database. At this point (using SaveOrUpdateCopy) I get a "row
> > was
> > > >>> > > > > updated or deleted...." error.
>
> > > >>> > > > > I just can't seem to find the right combination of attributes
> > and
> > > >>> > > > > method calls to do what I assume is a pretty normal process.
>
> > > >>> > > > > Here is a sample test.
>
> > > >>> > > > > Parent parent = CurrentSession.GetById(parentId);  //includes
> > > >>> logic to- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to