Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Akhilesh this is one way that comes to my mind (see below). I'm also learning Ibatis/MyBatis and gradually getting my grips into it. I take you want several inserts/updates to be included in a single transaction (performance in mind)? Similar to a batch update, wrap the batch in a single transaction. This example is based on IBatis 2.3.4</p> <p>In your DAO class you can have,</p> <pre><code>final SqlMapClient sqlMap = getSqlMapClient(); try { sqlMap.startTransaction(); sqlMap.startBatch(); for (final ClientDetails clientXXX : clientDetailsList) { createOrUpdateClientDetails(sqlMapClient, clientXXX); createOrUpdateClientAddressDetails(sqlMapClient, clientXXX.getAddressDetails()); createOrUpdateOtherXXXDetails(clientXXX.getXXXXX); //have similar private method } sqlMap.executeBatch(); sqlMap.commitTransaction(); } catch (final SQLException e) { throw new XXXException(e); } finally { try { sqlMap.endTransaction(); } catch (SQLException e) { throw new XXXException(e); } } private void createOrUpdateClientDetails(final SqlMapClient sqlMap, final List&lt;ClientDetails&gt; clientDetails) { for (final ClientDetails client: clientDetails) { if (client.getId() != null) { sqlMap.update("updateClientXXX", client); //your sqlmap method } else { sqlMap.insert("createClientXXX", client); //your sqlmap method } } } </code></pre> <p>However note that whenever you are using a batched set of statements the database generated keys will not be generated until you have called the executeBatch() method. This means if you are using <code>selectKey</code> to update your objects with the generated key(s) they will return null. <strong>If you have any object that requires the newly generated key as part of another dependent insert then you can have this insert/parent insert before the startBatch()</strong>. For e.g. AddressDetails and PhoneDetails will have the customer_id as FK?</p> <p>I would also look at your ClientDetails parent class again and see if if this can be simplified if possible. Again I'm uncertain if this is the approach you are after but I thought of sharing what I had in mind. Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload