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.  [ 4 posts ] 
Author Message
 Post subject: Initializing object graph for new domain object
PostPosted: Mon Aug 07, 2006 2:19 pm 
Newbie

Joined: Tue May 02, 2006 6:54 pm
Posts: 10
Location: Salt Lake City, Utah
I have a data access layer implemented using NHibernate and session-per-conversation pattern. What I'd like to do is to create new domain objects through this layer. These domain objects are bound to UI on WindowForms client. Because newly created domain objects may have null associations which are required on the client side I need a way to initialize object graph.

For example, Person has an Address which is not required.
I can initialize Address in a property getter when it is requested for binding etc., but when user doesn't enter any data into Address fields I have to make sure that Address is not being saved. There are many ways to make sure an empty address is not saved. The best I could come up was through Interceptor and some flag on domain object.

Another possibility is to initialize object graph in data access layer when domain object is created. I hate to have Initialize as a method in domain object but other alternatives I thought about don't seem to be worth it.

Am I missing something or there's no elegant way to handle this situation?

Andre


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 1:19 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
Hi Andre,

for this reason i prefer to work with unbound objects. I have a BindData() and UnbindData() in my forms where we bind and unbind our object graph manually to the user controls. So we are able to instantiate objects only when needed. Another advantage for me is the full control over the process. We can decide ourselves when the obeject graph needs to be updated with the user input, we can make any conversions needed to display our data.

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 08, 2006 11:55 am 
Newbie

Joined: Tue May 02, 2006 6:54 pm
Posts: 10
Location: Salt Lake City, Utah
luedi wrote:
Hi Andre,

for this reason i prefer to work with unbound objects. I have a BindData() and UnbindData() in my forms where we bind and unbind our object graph manually to the user controls. So we are able to instantiate objects only when needed. Another advantage for me is the full control over the process. We can decide ourselves when the obeject graph needs to be updated with the user input, we can make any conversions needed to display our data.

Regards
Klaus


Klaus,

Is this what you mean,

Form.BindData()
{
...
if(Person.Address = null)
Person.Address = new Address()
...
}

If so, this is our current solution that we'd like to avoid. There's still ugly issue of checking for modifications to Address so it wouldn't be saved as an empty domain object in database.

... or you are just binding to value object as opposed to domain object?

Thanks for reply!
Andre


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 12:24 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
Hi Andre,

we do it like this:

Code:
private void BindData()
{
  if(Person.Address != null)
  {
    txtStreet.Text = Person.Address.Street;
    ...
  }
   ...
}

...

private void UnbindData()
{
  if((txtStreet.Text.Length >0) ||
     (txtZip.Text.Length >0) ||
     ...)
  {
    Person.Address = new Adress();
    ...
  }
  ...
}


The decision, if an instance have to be created is made in UnbindData(). The check may become complex depending on the number of fields involved, but i can ensure that only the instances i need are created.

Regards
Klaus


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