Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6548051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:54:15+00:00 2026-05-25T11:54:15+00:00

I have a problem when I try to persist objects using multiple threads .

  • 0

I have a problem when I try to persist objects using multiple threads.

Details :

Suppose I have an object PaymentOrder which has a list of PaymentGroup (One to Many relationship) and PaymentGroup contains a list of CreditTransfer(One to Many Relationship again).

Since the number of CreditTransfer is huge (in lakhs), I have grouped it based on PaymentGroup(based on some business logic)
and creating WORKER threads(one thread for each PaymentGroup) to form the PaymentOrder objects and commit in database.

The problem is, each worker thread is creating one each of PaymentOrder(which contains a unique set of PaymentGroups).

The primary key for all the entitties are auto generated.

So there are three tables, 1. PAYMENT_ORDER_MASTER, 2. PAYMENT_GROUPS, 3. CREDIT_TRANSFERS, all are mapped by One to Many relationship.

Because of that when the second thread tries to persist its group in database, the framework tries to persist the same PaymentOrder, which previous thread committed,the transaction fails due to some other unique field constraints(the checksum of PaymentOrder).

Ideally it must be 1..n..m (PaymentOrder ->PaymentGroup-->CreditTransfer`)

What I need to achieve is if there is no entry of PaymentOrder in database make an entry, if its there, dont make entry in PAYMENT_ORDER_MASTER, but only in PAYMENT_GROUPS and CREDIT_TRANSFERS.

How can I ovecome this problem, maintaining the split-master-payment-order-using-groups logic and multiple threads?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:54:15+00:00Added an answer on May 25, 2026 at 11:54 am

    You’ve got options.
    1) Primitive but simple, catch the key violation error at the end and retry your insert without the parents. Assuming your parents are truly unique, you know that another thread just did the parents…proceed with children. This may perform poorly compared to other options, but maybe you get the pop you need. If you had a high % parents with one child, it would work nicely.

    2) Change your read consistency level. It’s vendor specific, but you can sometimes read uncommitted transactions. This would help you see the other threads’ work prior to commit. It isn’t foolproof, you still have to do #1 as well, since another thread can sneak in after the read. But it might improve your throughput, at a cost of more complexity. Could be impossible, based on RDBMS (or maybe it can happen but only at DB level, messing up other apps!)

    3) Implement a work queue with single threaded consumer. If the main expensive work of the program is before the persistence level, you can have your threads “insert” their data into a work queue, where the keys aren’t enforced. Then have a single thread pull from the work queue and persist. The work queue can be in memory, in another table, or in a vendor specific place (Weblogic Queue, Oracle AQ, etc). If the main work of the program is before the persistence, you parallelize THAT and go back to a single thread on the inserts. You can even have your consumer work in “batch insert” mode. Sweeeeeeeet.

    4) Relax your constraints. Who cares really if there are two parents for the same child holding identical information? I’m just asking. If you don’t later need super fast updates on the parent info, and you can change your reading programs to understand it, it can work nicely. It won’t get you an “A” in DB design class, but if it works…..

    5) Implement a goofy lock table. I hate this solution, but it does work—have your thread write down that it is working on parent “x” and nobody else can as it’s first transaction (and commit). Typically leads to the same problem (and others–cleaning the records later, etc), but can work when child inserts are slow and single row insert is fast. You’ll still have collisions, but fewer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when I try to persist my model. An exception is
I have this problem when i try to synchronize a observable list with listbox/view
I have a problem using the SSIS. I try to import data from database
Suppose I have this code: class Example(object): def the_example(self): itsProblem = "problem" theExample =
I have a problem getting my change(s) to data object retrieved using NHibernate to
I have a problem, private void button_Submit_Click(object sender, EventArgs e) { try { string
I have problem when I try insert some data to Informix TEXT column via
I have problem with base classes in WPF. I try to make a base
I have a problem and I will try to explain the issue: I have
I have some problem's with a simple application in JSF 2.0. I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.