Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA persistence using multiple threads
    text
    copied!<p>I have a problem when I try to persist objects using <strong>multiple threads</strong>.</p> <p><strong>Details :</strong></p> <p>Suppose I have an object <code>PaymentOrder</code> which has a list of <code>PaymentGroup</code> (One to Many relationship) and <code>PaymentGroup</code> contains a list of <code>CreditTransfer</code>(One to Many Relationship again).</p> <p>Since the number of <code>CreditTransfer</code> is huge (in lakhs), I have grouped it based on <code>PaymentGroup</code>(based on some business logic) and creating <em>WORKER</em> threads(one thread for each PaymentGroup) to form the <code>PaymentOrder</code> objects and commit in database.</p> <p>The problem is, each worker thread is creating one each of <code>PaymentOrder</code>(which contains a unique set of <code>PaymentGroup</code>s). </p> <p>The primary key for all the entitties are auto generated.</p> <p>So there are three tables, 1. PAYMENT_ORDER_MASTER, 2. PAYMENT_GROUPS, 3. CREDIT_TRANSFERS, all are mapped by One to Many relationship.</p> <p>Because of that when the second thread tries to persist its group in database, the framework tries to persist the same <code>PaymentOrder</code>, which previous thread committed,the transaction fails due to some other unique field constraints(the checksum of <code>PaymentOrder</code>). </p> <p>Ideally it must be 1..n..m (<code>PaymentOrder</code> ->PaymentGroup<code>--&gt;</code>CreditTransfer`)</p> <p>What I need to achieve is if there is no entry of <code>PaymentOrder</code> in database make an entry, if its there, dont make entry in <code>PAYMENT_ORDER_MASTER</code>, but only in <code>PAYMENT_GROUPS</code> and <code>CREDIT_TRANSFERS</code>.</p> <p>How can I ovecome this problem, maintaining the split-master-payment-order-using-groups logic and multiple threads?</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