-->
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.  [ 3 posts ] 
Author Message
 Post subject: Domain Modeling & NHibernate Struggles
PostPosted: Fri Jan 04, 2008 2:34 pm 
Newbie

Joined: Thu Dec 14, 2006 7:08 pm
Posts: 11
Hi,

I'm currently designing part of a system that needs is responsible for summarizing information on commission earnings and adjustments from sales and refunds respectively. I decided to model problem with the Account and AccountEntry concepts. The interface of my Account class in C# is roughly,

pulic class Account
{
// The net earned within a period
public Money Balance(DateRange)

public Iterator Sales(DateRange)

public Iterator Adjustments(DateRange)

//We only pay if the partner has meet the minimum earnings
public Bool HasMeetMinimum()

private IList<AccountEntry> _Entries = new List<AccountEntry>()
}


I'm hung up on a few things when I think about implementing the balance method which is just the sum of the account entries that fall within the range.

* I don't want to load all of the entries at once for a given account
because of how many there could be.

* I don't want my account class to have a dependency on data access.
I'm using Nhibernate for persistance.

I wondering if I have my responsibilities are the wrong place. Perhaps I should put the Account methods on a Repository. Or maybe it's possible to lazy load a collection based on the values of fields withing a class?
Your feedback is greatly appreciated.

--
Cheers,
Aeden


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 8:48 am 
Newbie

Joined: Tue Jan 09, 2007 5:24 am
Posts: 15
Hi aedenj - set your collection of AccountEntry objects to be lazy loaded.

I would create a property called Entries on the Account object (implementation not included):

private IList<AccountEntry> _entries = new List<AccountEntry>();
public IList<AccountEntry> Entries { get; set; }


In the mapping file for the Account object I'd map it with a bag:

<bag name="AccountEntry" lazy="true" ....


Please consult the NH documentation for the complete syntax on a bag.

That way you can access the Account object without loading all the entries.

Cheers,
Thomas


Top
 Profile  
 
 Post subject: Re: Domain Modeling & NHibernate Struggles
PostPosted: Tue Jan 08, 2008 12:31 pm 
Regular
Regular

Joined: Wed Jan 25, 2006 1:11 am
Posts: 118
Location: Copenhagen, Denmark
aedenj wrote:
* I don't want to load all of the entries at once for a given account
because of how many there could be.


You can make it lazy loaded and if its because you are worried about fetching to many objects when they are initialized you can utilize the batch fetching feature

aedenj wrote:
* I don't want my account class to have a dependency on data access.
I'm using Nhibernate for persistance.


Youre assumptions about the repository is right on, i excpect that you want some sort of filtering of the collection, and for that you have to use a HQL/Criteria query and this should obviously not be in you model so you need a layer where you can ask for Business entities filled with data from your UI


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