flowable/flowable-engine · error · FlowableException
Query return " + results.size() + " results instead of max 1
Error message
Query return " + results.size() + " results instead of max 1
What it means
Result-shape guard in AbstractNativeQuery.executeSingleResult: singleResult() was called but the native query returned more than one row (count included in message); the caller must narrow the query or use list().
Solutions
- Add a where-clause/limit so the native query returns exactly one row
- Use list() instead of singleResult() when multiple rows are expected
Example fix
// before
Object r = managementService.createTableQuery()
.sql("SELECT * FROM ACT_RU_EXECUTION WHERE PROC_INST_ID_ = #{pid}")
.singleResult();
// after
Object r = managementService.createTableQuery()
.sql("SELECT * FROM ACT_RU_EXECUTION WHERE PROC_INST_ID_ = #{pid} LIMIT 1")
.singleResult(); Defensive patterns
Strategy: validation
Validate before calling
// ensure uniqueness before singleResult()
List<Map<String,Object>> all = managementService.createTableQuery()
.sql("SELECT * FROM ACT_RU_EXECUTION WHERE PROC_INST_ID_ = #{pid}").list();
if (all.size() > 1) throw new IllegalStateException("expected at most 1, got " + all.size()); Try / catch
try {
return nativeQuery.singleResult();
} catch (FlowableException e) {
if (e.getMessage().contains("instead of max 1")) {
return nativeQuery.list().get(0);
}
throw e;
} Prevention
- Add LIMIT 1 to native SQL used with singleResult()
- Restrict WHERE clauses to unique keys
- Prefer .list() when multiplicity is possible
When it happens
Trigger: Calling nativeQuery().singleResult() (or executeSingleResult) when the native SQL matches multiple rows — e.g. missing LIMIT 1 or a WHERE clause that isn't unique.
Common situations: Native SQL without LIMIT/TOP returned several matches; unique constraint assumptions broken by duplicate rows; developer used singleResult() assuming at most one row.
Related errors
- Query return " + results.size() + " results instead of max 1
- Query return " + results.size() + " results instead of max 1
- activatedBefore is null
- activity tenant id is null
- activity tenant id is null
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/15243d590c484b78.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/query/AbstractNativeQuery.java:133
}
}
public abstract long executeCount(CommandContext commandContext, Map<String, Object> parameterMap);
/**
* Executes the actual query to retrieve the list of results.
*
* @param commandContext
* @param parameterMap
*/
public abstract List<U> executeList(CommandContext commandContext, Map<String, Object> parameterMap);
public U executeSingleResult(CommandContext commandContext) {
List<U> results = executeList(commandContext, generateParameterMap());
if (results.size() == 1) {
return results.get(0);
} else if (results.size() > 1) {
throw new FlowableException("Query return " + results.size() + " results instead of max 1");
}
return null;
}
}
View on GitHub (pinned to d6d39ce1c6)