java - Hibernate: Updating OneToMany relationship -


i have parent list of child mapped.

may know how update list of child when update parent

example:

a parent p1 have child b c.

i decided delete b , add d

so parent p1 have child c d in database.

currently merely delete child belongs parent p1 , repopulate chid(a c d) again... believe there more simple way of doing so.

i know task quite sensitive, please kind enough let me know need set ensure child inserted , deleted properly.

new question:

1) there way lazy update/delete relationship? have list fetchtype.lazy, when updating data, might not wish load relationship or update it.

2) if list have item b c, removed item c , dto.save(). item c deleted?

here mapping update child using parent -

@entity @table(name = "company") @sequencegenerator(name="companyseq", sequencename="companyseq", allocationsize=1) public class company implements serializable {      private static final long serialversionuid = 1l;      /*      * customer company details       */      @id     @generatedvalue(strategy = generationtype.sequence, generator = "companyseq")     @column(name = "company_id")     private integer id;      @column(name="company_name")     private string name;      @onetomany(cascade = cascadetype.all, fetch = fetchtype.lazy)     @joincolumn(name = "company_id",nullable=false)     @orderby(clause = "product_name" )     @foreignkey(name = "fk_company_product")          private list<product> products = new arraylist<product>();       }     @entity @table(name = "product") @sequencegenerator(name="companyproductseq", sequencename="company_product",  allocationsize=1) public class product implements serializable{      /**      * serialversion id      */     private static final long serialversionuid = 4073418246832063389l;      @id     @generatedvalue(strategy = generationtype.sequence, generator = "companyproductseq")     @column(name = "product_id")     private integer id;      @manytoone(fetch=fetchtype.lazy)     @joincolumn(name = "company_id", updatable = false, insertable = false, nullable=false)       private company companyid;          @column(name = "product_name")     private string name;      } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -