Here I am working on a project which is to insert a new audit record in a table. (e.g. new_vale vs old_value), with pairs of fields that need to be updated.
Problem: I am trying to solve:
session.save () does not perform "INSERT" , but instead performs an "UPDATE" .
private void updateCollabPoApprovaForASN(CollabPoApprovalKey key, PurchaseOrderUpdateASN updateAsn){
CollabPoApproval collabPoApproval = this.collabPoApprovalGateway.findById(key);
compareAndSetChangedValue(updateAsn, collabPoApproval);
key.setChangeId(generateId());
collabPoApproval.setKey(key);
this.collabPoApprovalGateway.save(collabPoApproval);
}
Basically, I did this, I use a hibernate query to grab an existing record, and then I change the primary key, manually setting the identifier, and I update these pair of validation fields. Finally, save it back to the database.
SQL Generated:
update CollabPoApproval set OLD_DRAWING_NUMBER=?, NEW_DRAWING_NUMBER=? ... where ID=? and SU_ID=? and PO=? and LINE=?
Table Background :
, , , TimeStamp+[0-999]
(, 20150412113637011
), , .
4 , , . , , .
, , :
Google/StackOverFlow Search .
( , ):
<generator class="assigned" />
hbm composit-id :
<composite-id class="CollabPoApprovalKey" name="key">
<key-property name="Id" column="ID" type="long" />
<key-property name="suId" column="SU_ID" type="integer" />
<key-property name="po" column="PO" type="integer" />
<key-property name="line" column="LINE" type="short" />
<generator class="assigned" />
</composite-id>
save(String entityName, Object object)
this.collabPoApprovalGateway.save("CollabPoApproval",CollabPoApproval)
Trid saveOrUpdate(Object object)
.