Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do the following for e.g. using iBatis (I'm using iBatis version 2.3.4 so this example is based on that). Creating a batch of statements can improve performance. It is also important to note to wrap the batch in a single transaction as if it is not wrapped then a new transaction will be started for each statement (performance can be an issue depending on batch size I believe). </p> <p>See example below. You will notice that the start of the batch <code>startBatch()</code> is only started after the parent record is updated or inserted. This is because database generated keys will not be generated until you have called the <code>executeBatch()</code>. This means if you are using <code>selectKey</code> to update your objects with the generated keys they will return null. This is why the creation/update of the Parent record is before the <code>startBatch()</code> statement. Hope this helps as an example for you.</p> <pre><code>try { sqlMap.startTransaction(); if (parent.getId == null) { sqlMap.insert("createParent", parent); } else { sqlMap.update("updateParent", parent); } sqlMap.startBatch(); for (final Child exapleChild: parent.getChildren()) { exapleChild.setParentId(parent.getId); sqlMap.insert("createChildForParent", objectReference1); } sqlMap.executeBatch(); sqlMap.commitTransaction(); } catch (final SQLException e) { throw new XXXException(e); } finally { try { sqlMap.endTransaction(); } catch (SQLException e) { throw new XXXException(e); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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