hibernate update for a one to many relationship when associate table gets more rows -


entity

@table(name = "service") public class service implements serializable {      /** constant serialversionuid. */     private static final long serialversionuid = 1l;      /** serviceid. */     @id     @sequencegenerator(name = "service_seq", sequencename = "service_seq", allocationsize = 1, initialvalue = 1)     @generatedvalue(strategy = generationtype.sequence, generator = "service_seq")     @column(name = "service_id", columndefinition = "number(10)")      /** description. */     @column(name = "description", columndefinition = "varchar(500)")     private string description;       @onetomany(targetentity = serviceaddress.class, mappedby = "service",      cascade = cascadetype.all, orphanremoval = true)      private set<serviceaddress> serviceaddressset;  } 

@entity @table(name = "address") public class serviceaddress implements serializable {      /** constant serialversionuid. */     private static final long serialversionuid = 1l;     @id     @generatedvalue(strategy = generationtype.sequence, generator = "service_address_seq")     @column(unique = true, name = "service_address_id", columndefinition = "number(10)")     private int serviceaddressid;      /** service address. */     @column(name = "address", columndefinition = "varchar(200)" ,nullable = false)     private string address;      @manytoone     @joincolumn(name = "service_id",nullable = false)     private service service;      /**      * gets services.      *       * @return services      */     public service getservice() {         return service;     }      /**      * sets services.      *       * @param services      *            services set      */     public void setservice(service service) {         this.service = service;     } }  

these 2 of entity classes , want delete multiple rows in address table particular serviceid using hibernate. couldn't use serviceid query because in address table mapped service object.

session.begintransaction();

    service service = session.load(service.class, 114);      criteria c = session.createcriteria(address.class);      c.add(restrictions.eq("service", service));      list<address> list = c.list();      (address : list) {          session.delete(as);      }      session.gettransaction().commit(); 

hope !!


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -