cancel
Showing results for 
Search instead for 
Did you mean: 

DbSqlSession FlushInserts with Custom Entities

goodboy
Champ in-the-making
Champ in-the-making
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. Smiley Happy

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.

2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
You're correct .. there shouldn't be a remove for the second one. Fixed here: https://github.com/Activiti/Activiti/commit/b03e48f7f0adf970c67b37c2e4a6924ed36ce569

goodboy
Champ in-the-making
Champ in-the-making
Smiley Happy

Thanks! Joram