spring - Cascading not saving the reference table data -
cascading not saving details
orders table
create table orders ( order_id numeric(10,0) not null, test_id numeric(5,0), constraint orders_pkey primary key (order_id), constraint fk_order_user_doneby foreign key (done_by) references user_mast (user_id) match simple on update no action on delete no action }
reference table
create table refout_order_hdr ( ref_inst_id numeric(8,0), status character varying(1), ref_out_id numeric(10,0) not null, order_id numeric(10,0), constraint "refout_order_pkey primary key (ref_out_id)" primary key (ref_out_id), constraint "ref_out_fkey_order_id order_id)" foreign key (order_id) references orders (order_id) match simple on update no action on delete no action )
there 1 many relation between orders & refrence(order_id)
entity class reference
/** * */ private static final long serialversionuid = 1l; private long refoutid; private cdcinstitutes instmast; private string status; @jsonignore private orders orders; //------other getters , setters there -------------// @manytoone(fetch = fetchtype.lazy) @joincolumn(name="order_id") public orders getorders() { return orders; } public void setorders(orders orders) { this.orders = orders; //------other getters , setters there -------------//
entity class orders
private long orderid; private testmast testmast; private set<refoutorder> refoutorder; @onetomany(mappedby="orders", fetch=fetchtype.lazy, cascade = {cascadetype.merge, cascadetype.persist } ) public set<refoutorder> getrefoutorder() { return refoutorder; } public void setrefoutorder(set<refoutorder> refoutorder) { this.refoutorder = refoutorder; }
even though cascading set while saving orders entity, reference table orderid not saving. other fields set.
//service layer
for( orderedlistdto orderedlistdto : radioorderlist){ if(orderedlistdto != null && orderedlistdto.getordersdto() != null){ orderedlistdto.getordersdto().settesttype(serviceconstants.test_type_radialogy); orderedlistdto.getordersdto().setvisitid(visitdto.getvisitid()); neworderdtos.add(orderedlistdto.getordersdto()); } } list<ordersdto> resultlist = ordersservice.saveorderslist(new arraylist<>(neworderdtos));
//save method called here
@override @transactional public list<ordersdto> saveorderslist(list<ordersdto> orderslist) throws visitmastexception { if(orderslist == null){ //need throws exception atleast 1 order update or save order. } list<ordersdto> resultlist = new arraylist<ordersdto>(); for(ordersdto order: orderslist){ try{ order.setinstcode(institutionservice.getinstcode()); order.setcreateddate(new date()); order = super.saveoneentity(order); resultlist.add(order); } catch (genericexception ge) { throw new visitmastexception(ge, ge.getrootcausemessage()); } catch (institutenotfoundexception e) { throw new visitmastexception(visitmastexception.internal_server_error, "", e, messagesource.getmessage(codeenum.inst_code_not_found.getvalue(), null, locale.english)); } } return resultlist; }
saving logic save 1 entity @ time
Comments
Post a Comment