-->
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.  [ 2 posts ] 
Author Message
 Post subject: Lazy
PostPosted: Wed Feb 01, 2006 1:47 am 
Newbie

Joined: Fri Jan 27, 2006 3:14 pm
Posts: 2
Could you please help me?
There is a case as bellow :
I have two classes VocherBDO and FinancialPeriodBDO

VocherBDO , FinancialPeriodBDO are lazy and all their properties are virtual
The problem is :
When loading VocherBDO, FinancialPeriodBDO is loaded whiteout any method call of FinancialPeriodBDO
VocherBDO.cs
*********************************************************************
using System;
using System.Collections;
using System.Reflection;

namespace CommonLibrary.TotalBusinessDataObject
{
///CommonLibrary.TotalBusinessDataObject.VocherBDO
/// <summary>
/// Summary description for VocherBDO.
/// </summary>
[Serializable]
public class VocherBDO : BaseBusinessDataObject
{
public VocherBDO(){}
private int _Id;
private string _VocherNumber;
private string _Date;
private FinancialPeriodBDO _FinancialPeriodBDO;

public virtual int id
{
set{ _Id = value; }
get{ return _Id; }
}

public virtual string vocherNumber
{
set{ _VocherNumber = value; }
get{ return _VocherNumber; }
}

public virtual string date
{
set{ _Date = value; }
get{ return _Date; }
}

public virtual FinancialPeriodBDO financialPeriodBDO
{
set { _FinancialPeriodBDO = value; }
get { return _FinancialPeriodBDO; }
}


}
}

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="CommonLibrary.TotalBusinessDataObject.VocherBDO,CommonLibrary"
table="voucherView"
dynamic-update="true"
dynamic-insert="true"
lazy ="true">

<id name="id" column="id" type="Int32">
<generator class="identity" />
</id>

<property name="vocherNumber" column="vocherNumber" type="String" update="true" insert="true" />
<property name="date" column="date" type="String" update="true" insert="true" />

<many-to-one name="financialPeriodBDO" class="CommonLibrary.TotalBusinessDataObject.FinancialPeriodBDO, CommonLibrary"
column="financialPeriodId" not-null="true" outer-join="false"
update="false" insert="false" />
</class>
</hibernate-mapping>

*********************************************************************
FinancialPeriodBDO.cs

using System;

namespace CommonLibrary.TotalBusinessDataObject
{
/// <summary>
/// Summary description for FinancialPeriod.
/// </summary>
[Serializable]
public class FinancialPeriodBDO : BaseBusinessDataObject
{
public FinancialPeriodBDO()
{}
private int _Id;
private string _Code;
private string _Title;

public virtual int id
{
set{ _Id = value; }
get{ return(_Id); }
}
public virtual string code
{
set{ _Code = value; }
get{ return(_Code); }
}
public virtual string title
{
set{ _Title = value; }
get{ return(_Title); }
}
}
}

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="CommonLibrary.TotalBusinessDataObject.FinancialPeriodBDO, CommonLibrary"
table="financialPeriod"
lazy ="true">

<id name="id" column="id" type="Int32">
<generator class="identity" />
</id>
<property name="code" column="code" type="String" />
<property name="title" column="title" type="String" />
/class>
</hibernate-mapping>
*********************************************************************

public void GetVocher()
{
ISession aSession = sessionFactory.OpenSession();
VocherBDO aVocherBDO = new VocherBDO();
aSession.Load(aVocherBDO,1);
sessionFactory.Close();

}


Top
 Profile  
 
 Post subject: Tried ur example
PostPosted: Wed Feb 01, 2006 4:16 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
I just tried your example and I see it working correctly. After
aSession.Load(aVocherBDO,1);

financialPeriodBDO in aVocherBDO is a proxy object. I see a new SQL getting fired after I call
Console.WriteLine(aVocherBDO.financialPeriodBDO.code);

I think in this case the lazy is working correctly.


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