Hi,
I'm using NHibernate and C#. I've problem using the 'lazy' directive. When I try to access a set (in the case below, is the parentDocs of the Document class) which has lazy set to true, I hit error (the error line is on the om.parentDocs.Count) stating that system use lazy instantiation since there is no session available. As such, I've added line to open/get the session again (see=NHibernateSessionUtil.Session will give open session). But this doesn't help.
Hope you guides tell me which area I should take note/modify when I set to 'lazy'? Or my code can't call like this (i.e. om.parentDocs.Count is invalid) or I need to explicitly call a HQL query to get the count result?
thanks in advance,
jL
code below:
public ArrayList getRootParentDocs(Document om)
{
ArrayList alResult = new ArrayList();
Document doc = new Document();
sess = NHibernateSessionUtil.Session;
ITransaction tx = sess.BeginTransaction();
if (om.parentDocs.Count == 0)
{
alResult.Add(om);
tx.Commit();
sess.Close();
}
else {
for (IEnumerator ie = om.parentDocs.GetEnumerator(); ie.MoveNext(); )
{
doc = (Document)ie.Current;
getRootParentDocs(doc);
}
sess.Close();
}
return alResult;
}
|