Regular |
|
Joined: Fri Nov 21, 2003 10:23 am Posts: 81
|
The code below does not force hibernate to delete existing child records.
This code only trying to insert new childs.
Note: InstrumentBondStatic with instrumentId=710 is existing in database, and have also some child records.
Code: session.beginTransaction();
InstrumentBondStatic bond = new InstrumentBondStatic(); bond.setInstrumentId(new Long(710)); bond.setCurrencyId("USD"); bond.setName("test_bond");
// create payments Set payments = new HashSet();
InstrumentBondIR bondIR_0 = new InstrumentBondIR(); bondIR_0.setAdjustment(new Double(11)); bondIR_0.setAdjustmentDate(new java.util.Date()); bondIR_0.setSwapBranch("d"); bondIR_0.setInstrumentBondStatic(bond); payments.add(bondIR_0);
InstrumentBondIR bondIR_1 = new InstrumentBondIR(); bondIR_1.setAdjustment(new Double(21)); bondIR_1.setAdjustmentDate(new java.util.Date()); bondIR_1.setSwapBranch("e"); bondIR_1.setInstrumentBondStatic(bond); payments.add(bondIR_1);
InstrumentBondIR bondIR_2 = new InstrumentBondIR(); bondIR_2.setAdjustment(new Double(31)); bondIR_2.setAdjustmentDate(new java.util.Date()); bondIR_2.setSwapBranch("f"); bondIR_2.setInstrumentBondStatic(bond); payments.add(bondIR_2);
// add new payments to bond bond.setPayments(payments);
session.saveOrUpdate(bond); session.flush(); session.connection().commit(); Mapping fragmentsParent: Code: /** * @hibernate.set inverse="true" cascade="all-delete-orphan" lazy="true" * @hibernate.collection-key column="instrumentId" * @hibernate.collection-one-to-many class="com.domainmodel.InstrumentBondIR" */ public Set getPayments() { return payments; } Child: Code: /** * @hibernate.many-to-one column="instrumentId" class="com.pxpfs.excom2.finance.domainmodel.InstrumentBondStatic" not-null="true" */ public InstrumentBondStatic getInstrumentBondStatic() { return instrumentBondStatic; }
SQL log without deleting old child records
Hibernate: select InstrumentBondIRId_SEQ.NEXTVAL from dual Hibernate: select InstrumentBondIRId_SEQ.NEXTVAL from dual Hibernate: select InstrumentBondIRId_SEQ.NEXTVAL from dual Hibernate: insert into INSTRUMENT_BOND_IR_TBL (instrumentId, swapBranch, cashFlowDate, interestRateType, fixedRate, interestRateId, adjustmentDate, addValue, mulValue, floor, cap, collar, adjustment, cashFlowFixing, periodEndDate, instrumentBondIRId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Hibernate: update INSTRUMENT_STATIC_TBL set marketId=?, exchangeId=?, exchangeRouteId=?, currencyId=?, isinCode=?, symbol=?, name=?, longName=?, externalIDType=?, externalId=?, wknNr=?, status=?, lastUpdatedDate=?, lastUpdatedTime=?, implementationDate=?, implementationTime=?, internalType=?, roundLot=?, oddLot=?, tickSize=?, tradableFrom=?, tradableFromTime=?, tradableUpTo=?, tradableUpToTime=?, issuerId=?, issuerName=?, issueDate=?, issueTime=?, instType=?, termStructure=?, instrumentFilter=?, RVTradable=?, RVVisibility=?, assetClassId=?, calendarId=?, internalRating=?, isSpecialRiskFree=? where instrumentId=? Hibernate: update INSTRUMENT_BOND_STATIC_TBL set subType=?, issueRate=?, maturityDate=?, maturityRate=?, faceValue=?, bookValue=?, adjustment=?, termModel=?, initIndex=?, initRate=? where instrumentId=?
|
|