-->
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.  [ 1 post ] 
Author Message
 Post subject: General Question about Getting Started Example
PostPosted: Wed Jul 30, 2008 10:01 pm 
Newbie

Joined: Thu Jun 02, 2005 3:25 pm
Posts: 7
Location: Traverse City, MI
I have a question about the getting started sample for NHibernate. It was my impression that an ISession should stay open for a unit of work. The ProductRepository in the getting started example shows that each CRUD method opens a new ISession, starts a Transaction, then commits it and closes the ISession?

Code:
public Product GetByName(string name)       
{           
    using (ISession session = NHibernateHelper.OpenSession())
    {                 
            Product product = session                   
            .CreateCriteria(typeof(Product))                   
            .Add(Restrictions.Eq("Name", name))                   
            .UniqueResult<Product>();               
            return product;           
     }       
}


What happens if the product object has a lazy loaded associated class like Orders? Would fetching the Orders collection cause an error on this object because the ISession it is connected to is closed?

Am I missing something?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.