Hi all.
We have something like this:
public Class Question {
public int Id { get, set }
public int AreaId { get, set }
public Area RelatedArea { get { return Area.get(this.AreaId); } }
}
Each time we use a Question object and call the Area property with some like:
myQuestion.RelatedArea.AreaName;
myQuestion.RelatedArea.AreaPhone;
IBatis goes to access the database and ask for "select * from area
where Id = ... (the AreaId)...":
myQuestion.RelatedArea.AreaName; (one SQL)
myQuestion.RelatedArea.AreaPhone; (another SQL)
We want to limit the access to database with:
class Question {
private Area _relatedArea;
public Area RelatedArea {
get {
if(_relatedArea == null) { _relatedArea = Area.get(IdArea); }
return _relatedArea;
}
}
With this solution iBatis just access one time the DB because in the
first QuestionObject.RelatedArea the Area is obtained, and the next
.RelatedArea comes from memory.
My question is: is there any other way, through a pattern or a memory
Cache for iBatis?
Thanks again and sorry for my poor English! :S