-->
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: Saving a class with partial information?
PostPosted: Sat Jan 09, 2010 3:59 am 
Newbie

Joined: Mon Nov 09, 2009 3:00 pm
Posts: 3
I am running into a problem and I am not sure how to solve it: How could I save a mapped class that doesn't have all fields specified? I am looking for a solution that would work with a n-tier website with an optimistic locking strategy in place.

Example: There is a class, Company. Company has several fields, id, name, website, employees, etc. This company record will exist in a core database that other modules will use. However, not all modules may care or allow for all of the traits of a Company. Module A may only allow for the name and number of employees to be modified. How can a developer for module A quickly save the new information it may have for the Company record?

Is it really a matter of having to do a database, on some tier, call to fetch the, hopefully, original graph? Is there something that I am missing?

Thanks for your help.


Top
 Profile  
 
 Post subject: Re: Saving a class with partial information?
PostPosted: Sun Jan 10, 2010 2:05 pm 
Newbie

Joined: Wed Dec 23, 2009 12:38 pm
Posts: 14
Is company class used by many other classes and each time there are different attributes which are important ?

I will suggest you handle this in the business layer instead of database layer.

You can ensure that all required fields for database layer are taken care of either with actual values or default values in the absence of actual value provided by the user. This can be done with the help of utility function.

A has 1,2,3,4,5 attributes

A saved with B needs only 4,5
A saved with C needs only 1,2
A saved with D needs only 1,5

Have utility function which will take care of mandatory and optional values and send populated 1,2,3,4,5 to database layer.


Top
 Profile  
 
 Post subject: Re: Saving a class with partial information?
PostPosted: Sun Jan 10, 2010 2:44 pm 
Newbie

Joined: Mon Nov 09, 2009 3:00 pm
Posts: 3
I think I understand what you're saying, but I am looking at a scenario of updating a Company record.

In the database there is a record, it's at version 1 status. Id: 1, Name: Jeff's Co, Website: www.jeffsco.com, Employees: 10, etc.

Module A loads up that company, and presents the Name, and Website to the user to be edited. Id is thrown into a hidden field.
User makes any relevant changes to Name and/or website, then clicks save.

What is the best way to save the updated information? Without overwriting Employees or other fields? Am I going to have to take the database hit to reload the object?


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.