• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Persisting Business Objects

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm wondering how persistence of nested business objects should be handled.
For example, lets assume I have an (oversimplified) class design as follows:

Employee
| |
Address Name

In other words, an Employee class which is composed of both an Address and Name class. Address is a discrete class which can be saved independently of Employees (eg. Customer class also contains an Address). Per best practice, I have a DAO that only concerns itself with loading and saving Address objects:

class AddressDAO{

public static void save(Address addr){

//save address object

}

public static void delete(Address addr){

//delete address object

}

public static void add(Address addr){

//add address object

}


public static Address get(String key ){

//get address object

}
}

I similiary have an EmployeeDAO class that laods/saves Employee objects. My question: is it appropriate to simply call AddressDAO.save from EmployeeDAO.save? Is there a cleaner approach?

[ November 06, 2008: Message edited by: Mitch Hartner ]
[ November 06, 2008: Message edited by: Mitch Hartner ]
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there a cleaner approach?



A more efficient approach would be to use CMP Entity EJB or an ORM framework such as Hibernate to handle this for you, in my opinion. Aside from that, what you mention will work if you write it correctly.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic