java - DAO persistence: only one method to store a complex data object? -


here have:

public final class product {   integer productid;  string description;  ...   public product(final integer productid, final string descripcion, ...) {     this.product_id = productid;     this.description = description;     ...  }   public integer getproductid() { ... }  public string getdescription() {...}   ...  } 

an then:

public final productdetails {   integer productid;  string serialnumber;  ...  public productdatails(final integer productid, final serialnumber, ...){ ... }  public intger getproductid() { ... }  public string getserialnumber { ... }  ...  } 

so, in order build dao persists data 2 classes contain, question if practice follows:

    public interface iproductdao {        public void saveproduct(final product product);       public void saveproductdetails(final productdetails productdetails);      } 

or:

public interface iproductdao {  public void saveproduct(final product product, final productdetails productdetails); 

i have been taking in consideration refactor 2 classes 1 follows:

public final class product {   integer productid;  string description;  productdetails productdetails;  ...   public product(final productid productid, final string description, final productdetails productdetails,...) {     if(productid!=productdetails.getproductid())       throw new illegalargumentexception("productid not same");     ...   } 

}

so:

 public interface iproductdao {                   public void saveproduct(final product product);                                 } 

i know 1 'natural' approach according best software development practices. if there other approaches, welcomed well.

best approach have 2 java classes. 1 product , second productdetails in have more details of product. when user clicks on product, can fetch class show more details particular item.

so basic details required shown in teh search page can come in product class.

class product {   integer productid;  string description;  @onetoone  @basic(fetch = fetchtype.lazy)  productdetails details;   public product(final integer productid, final string descripcion, ...) {     this.product_id = productid;     this.description = description;     ...  }    public integer getproductid() { ... }  public string getdescription() {...}   ...  } class productdetails{  integer productid;//any id string description; //storing hd picture , other getters , setters } //details of class } 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -