AnsweredAssumed Answered

DbSqlSession FlushInserts with Custom Entities

Question asked by goodboy on Mar 14, 2016
Latest reply on Mar 15, 2016 by goodboy
Hi awesome ppl,


I'm having a little strange error. I have two custom entities (HistoricProcessInstanceEntity and CommentEntity), when the process is finalized the method DbSqlSession.flushInserts() is called till were it's ok. :)

But inside this method(flushInserts), there is a second for that iterates over the insertedObjects keySet to get the object class implementation. When this list of objects was more then one custom entity class, on the second key of the list this error occurs:


java.util.ConcurrentModificationException: null
at java.util.HashMap$HashIterator.nextNode(Unknown Source)
at java.util.HashMap$KeyIterator.next(Unknown Source)
at org.activiti.engine.impl.db.DbSqlSession.flushInserts(DbSqlSession.java:796)
at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:611)
at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:212)
at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:138)


This is happening because inside the method flushPersistentObjects a remove is done on the insertedObjects list.

I'm using Activiti 5.19.0.


protected void flushInserts() {
     
     // Handle in entity dependency order
    for (Class<? extends PersistentObject> persistentObjectClass : EntityDependencyOrder.INSERT_ORDER) {
      if (insertedObjects.containsKey(persistentObjectClass)) {
         flushPersistentObjects(persistentObjectClass, insertedObjects.get(persistentObjectClass));
      }
    }
   
    // Next, in case of custom entities or we've screwed up and forgotten some entity
    if (insertedObjects.size() > 0) {
       for (Class<? extends PersistentObject> persistentObjectClass : insertedObjects.keySet()) {
         flushPersistentObjects(persistentObjectClass, insertedObjects.get(persistentObjectClass));
       }
    }
   
    insertedObjects.clear();
  }

   protected void flushPersistentObjects(Class<? extends PersistentObject> persistentObjectClass, List<PersistentObject> persistentObjectsToInsert) {
     if (persistentObjectsToInsert.size() == 1) {
        flushRegularInsert(persistentObjectsToInsert.get(0), persistentObjectClass);
     } else if (Boolean.FALSE.equals(dbSqlSessionFactory.isBulkInsertable(persistentObjectClass))) {
        for (PersistentObject persistentObject : persistentObjectsToInsert) {
           flushRegularInsert(persistentObject, persistentObjectClass);
        }
     }   else {
        flushBulkInsert(insertedObjects.get(persistentObjectClass), persistentObjectClass);
     }
     insertedObjects.remove(persistentObjectClass);
  }


Dunno if i can change anything or call something before this custom entities inserts. To solve this problem.

Thanks.

Outcomes