flowable/flowable-engine · error · ActivitiException
Error while flushing EntityManager: " + pe.getMessage()
Error message
Error while flushing EntityManager: " + pe.getMessage()
What it means
Thrown by EntityManagerSessionImpl.flush() when the JPA provider raises a generic PersistenceException during EntityManager.flush(). This is the catch-all persistence failure (SQL errors, constraint violations, mapping problems) rethrown as ActivitiException, with the provider message appended.
Source
Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/EntityManagerSessionImpl.java:61
}
public EntityManagerSessionImpl(EntityManagerFactory entityManagerFactory, boolean handleTransactions, boolean closeEntityManager) {
this.entityManagerFactory = entityManagerFactory;
this.handleTransactions = handleTransactions;
this.closeEntityManager = closeEntityManager;
}
@Override
public void flush() {
if (entityManager != null && (!handleTransactions || isTransactionActive())) {
try {
entityManager.flush();
} catch (IllegalStateException ise) {
throw new ActivitiException("Error while flushing EntityManager, illegal state", ise);
} catch (TransactionRequiredException tre) {
throw new ActivitiException("Cannot flush EntityManager, an active transaction is required", tre);
} catch (PersistenceException pe) {
throw new ActivitiException("Error while flushing EntityManager: " + pe.getMessage(), pe);
}
}
}
protected boolean isTransactionActive() {
if (handleTransactions && entityManager.getTransaction() != null) {
return entityManager.getTransaction().isActive();
}
return false;
}
@Override
public void close() {
if (closeEntityManager && entityManager != null && !entityManager.isOpen()) {
try {
entityManager.close();
} catch (IllegalStateException ise) {
throw new ActivitiException("Error while closing EntityManager, may have already been closed or it is container-managed", ise);View on GitHub (pinned to d6d39ce1c6)
Solutions
- Read the chained PersistenceException cause for the provider-specific root cause (usually a SQLException)
- Verify DB schema matches the JPA entity mappings (hbm2ddl validation or migration tool)
- Fix constraint/data issues causing the flush failure
- Check database connectivity and connection pool health
Example fix
// before // fix at DB level, not code: // ERROR: duplicate key value violates unique constraint "orders_pkey" // after ALTER TABLE orders ALTER COLUMN id RESTART WITH <max_id + 1>; -- realign sequence
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-validate entity state
for (Object entity : entityList) {
if (entityManager.contains(entity) == false && entity.id == null) {
throw new IllegalArgumentException("Entity not managed and missing id: " + entity);
}
} Try / catch
try {
processEngine.getRuntimeService().setVariable(executionId, "orders", orderList);
} catch (ActivitiException e) {
Throwable root = e;
while (root.getCause() != null) root = root.getCause();
logger.error("JPA flush root cause", root);
throw e;
} Prevention
- Keep DB schema in sync with entity mappings (Flyway/Liquibase)
- Validate constraint-sensitive data before persisting entities as variables
- Monitor DB connectivity and pool exhaustion
When it happens
Trigger: Any persistence-layer failure during flush: SQL syntax/schema errors, unique constraint violations, detached entity issues, DB connection loss while writing JPA entity variable state.
Common situations: Schema out of sync with entity mappings; constraint violation when persisting the JPA entity stored as a process variable; database down or connection pool exhausted during flush.
Related errors
- Error while flushing EntityManager:
- no insert statement for ${entities.iterator().next().getClas
- no update statement for ${updatedObject.getClass()} in the i
- no delete statement for ${entity.getClass()} in the ibatis m
- couldn't get table counts
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/b8efb2e06914af68.
Report an issue: GitHub.