title: Java Object handling
body: <p>I want to update an audit table with request and response object with the time the request was sent and a response was sent back. The request and response object are the same, except for below. At the beginning of the for loop, the request object does not have all fields set initially.</p>
  
  <p>While the loop executes, I execute the <code>updateTax</code> method and get the object updated and my response object will have all the fields in the object set.</p>
  
  <p>At the end of the loop I want to log the request and response object. From the code below even though I set <code>pTax</code> to <code>pTaxRequest</code>, <code>pTaxRequest</code> changes values since <code>pTax</code> changes, so my request and response remains same.</p>
  
  <p>Here request is <code>pTaxRequest</code>, response would be <code>pTax</code> whenever it gets updated.</p>
  
  <pre><code>for(PTax pTax : pFaxTran.getPTaxList()){
    PTax pTaxRequest = pTax;
    ///.....
  
    pTax gets updated here
    ......
  
    pTax = updateTax();
  
    ......//
    pTaxMapper.insertPTax(startTime, endTime, pTaxRequest, pTax)
  }
  </code></pre>
  
  <p>One option would be do an insert to the audit table with the request at the beginning and update the audit table the same object as response in the end. But that would be 2 calls to DB.</p>
  
  <p>Is there any other way that I can achieve the same?</p>