flowable/flowable-engine · error · ActivitiException

Entity does not exist: -

Error message

Entity does not exist:  - 

What it means

findEntity performs EntityManager.find(entityClass, primaryKey); if the persistence layer returns null, the engine throws this ActivitiException because the stored variable references an entity row that no longer exists.

Source

Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/JPAEntityMappings.java:134

        EntityMetaData metaData = getEntityMetaData(entityClass);
        if (metaData == null) {
            throw new ActivitiIllegalArgumentException("Class is not a JPA-entity: " + className);
        }

        // Create primary key of right type
        Object primaryKey = createId(metaData, idString);
        return findEntity(entityClass, primaryKey);
    }

    private Object findEntity(Class<?> entityClass, Object primaryKey) {
        EntityManager em = Context
                .getCommandContext()
                .getSession(EntityManagerSession.class)
                .getEntityManager();

        Object entity = em.find(entityClass, primaryKey);
        if (entity == null) {
            throw new ActivitiException("Entity does not exist: " + entityClass.getName() + " - " + primaryKey);
        }
        return entity;
    }

    public Object createId(EntityMetaData metaData, String string) {
        Class<?> type = metaData.getIdType();
        // According to JPA-spec all primitive types (and wrappers) are supported, String, util.Date, sql.Date,
        // BigDecimal and BigInteger
        if (type == Long.class || type == long.class) {
            return Long.parseLong(string);
        } else if (type == String.class) {
            return string;
        } else if (type == Byte.class || type == byte.class) {
            return Byte.parseByte(string);
        } else if (type == Short.class || type == short.class) {
            return Short.parseShort(string);
        } else if (type == Integer.class || type == int.class) {
            return Integer.parseInt(string);

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Recreate the missing row or complete/terminate the process instance referencing it
  2. Verify the engine's EntityManagerFactory/datasource configuration matches the database holding the entity
  3. Prevent deletion of entities still referenced by running process instances (FK/soft-delete)
  4. Handle ActivitiException when reading variables that may reference deleted entities

Example fix

// before
Order order = (Order) runtimeService.getVariable(executionId, "order"); // throws if row deleted
// after
Order row = em.find(Order.class, storedId);
if (row != null) {
    Order order = (Order) runtimeService.getVariable(executionId, "order");
} else {
    runtimeService.removeVariable(executionId, "order");
}
Defensive patterns

Strategy: try-catch

Validate before calling

Object exists = em.find(Order.class, storedId);
if (exists == null) {
    runtimeService.removeVariable(executionId, "order");
}

Try / catch

try {
    Order order = (Order) runtimeService.getVariable(executionId, "order");
} catch (ActivitiException e) {
    if (e.getMessage().startsWith("Entity does not exist")) {
        // row was deleted; recover or remove the variable
        runtimeService.removeVariable(executionId, "order");
    } else { throw e; }
}

Prevention

When it happens

Trigger: Reading a JPA entity process variable whose underlying database row was deleted between variable creation and lookup; wrong EntityManagerFactory/persistence unit configured so find runs against another database.

Common situations: Entity purged by a cleanup job while the process instance still references it; pointing the engine at a different datasource in another environment (test vs prod); entity deleted by a cascade or manual SQL.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/ba491bc7e6fd0e65. Report an issue: GitHub.