0

I am using JTA with Helidon MP Framework for pushing data to oracle 18c ATP database. When I use High service(works fine with LOW) connection to ATP database, I am facing an error:

error: ORA-12838: cannot read/modify an object after modifying it in parallel

Here is the method in which I am trying to do Insert and delete operations.

    @Transactional(Transactional.TxType.REQUIRED)
    public void updateDeviceGroupMapCache(String flow, Map< String, Set<DeviceSummary>> deviceGroupMap, String deviceId) {

        List<DeviceGroupMapCache> insertedEntries = new ArrayList<>();
        List<DeviceGroupMapCache> deletedEntries = new ArrayList<>();

        // Step 5: Perform batch inserts and deletes
        processBatchEntries(insertedEntries, "I", 1000);
        processBatchEntries(deletedEntries, "D", 1000);

    }

    @Transactional(Transactional.TxType.REQUIRED)
    private void processBatchEntries(List<DeviceGroupMapCache> entries, String operation, int batchSize) {
        int count = 0;
        for (DeviceGroupMapCache entry : entries) {
            switch (operation) {
                case "I":
                    entityManager.persist(entry);
                    break;
                case "U":
                    entityManager.merge(entry);
                    break;
                case "D":
                    DeviceGroupMapCache reference = entityManager.getReference(DeviceGroupMapCache.class, entry.getDgmcId());
                    entityManager.remove(reference);
                   // entityManager.remove(entry);
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported operation: " + operation);
            }


            count++;

            if (count % batchSize == 0) {
                entityManager.flush();
                entityManager.clear();
            }
        }
        entityManager.flush();
        entityManager.clear();
      // entityManager.getTransaction().commit(); -- container Managed. so commit not possible
    }

Can you please help with the solution for this. Since the transaction is managed by container, I am not able to do explicit commit to complete the txn after an operation (be it insert or delete).

Have Tried userTransaction object approach and its failing with below error:

thread is already associated with a transaction!

1 Answers1

0

It is important to remember that an EntityManager cannot be shared across threads. I'm not sure why you're getting an error related to thread association here but check that first. There is nothing in Helidon that should behave any differently based on some service level of a cloud database. If you feel that you have discovered a bug, please file an issue in Helidon's issue tracker.

Laird Nelson
  • 15,321
  • 19
  • 73
  • 127