mybatis/mybatis-3 · error · ExecutorException
Error cloning cache key. Cause: {}
Error message
Error cloning cache key. Cause: {} What it means
While combining the row cache key of a nested result with its parent row key (used to deduplicate nested rows for collections/associations), cloning the CacheKey threw CloneNotSupportedException. CacheKey implements clone() and this is a defensive wrap that in practice should never fire; if it does, it indicates a corrupted/patched mybatis build or an unexpected runtime environment rather than a user mapping error.
Source
Thrown at src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java:1519
} else {
createRowKeyForUnmappedProperties(resultMap, rsw, cacheKey, columnPrefix);
}
} else {
createRowKeyForMappedProperties(resultMap, rsw, cacheKey, resultMappings, columnPrefix);
}
if (cacheKey.getUpdateCount() < 2) {
return CacheKey.NULL_CACHE_KEY;
}
return cacheKey;
}
private CacheKey combineKeys(CacheKey rowKey, CacheKey parentRowKey) {
if (rowKey.getUpdateCount() > 1 && parentRowKey.getUpdateCount() > 1) {
CacheKey combinedKey;
try {
combinedKey = rowKey.clone();
} catch (CloneNotSupportedException e) {
throw new ExecutorException("Error cloning cache key. Cause: " + e, e);
}
combinedKey.update(parentRowKey);
return combinedKey;
}
return CacheKey.NULL_CACHE_KEY;
}
private List<ResultMapping> getResultMappingsForRowKey(ResultMap resultMap) {
List<ResultMapping> resultMappings = resultMap.getIdResultMappings();
if (resultMappings.isEmpty()) {
resultMappings = resultMap.getPropertyResultMappings();
}
return resultMappings;
}
private void createRowKeyForMappedProperties(ResultMap resultMap, ResultSetWrapper rsw, CacheKey cacheKey,
List<ResultMapping> resultMappings, String columnPrefix) throws SQLException {
for (ResultMapping resultMapping : resultMappings) {View on GitHub (pinned to 008069adb1)
Solutions
- Verify only one MyBatis jar is on the classpath and it is the official unmodified artifact (mvn dependency:tree | grep mybatis).
- Clean and rebuild to eliminate stale instrumented classes.
- If the exception occurs, report a bug to the MyBatis project with the full stack trace — stock CacheKey cannot throw this.
Defensive patterns
Strategy: try-catch
Validate before calling
// verify a clean classpath at startup new org.apache.ibatis.cache.CacheKey().clone(); // must never throw; smoke-test the mybatis jar
Try / catch
catch (ExecutorException e) when e.getMessage().contains("Error cloning cache key") -> treat as environment/classpath defect: fail startup and require dependency audit rather than continuing with possibly-corrupted mapping state. Prevention
- Pin a single official mybatis version via dependency management; ban duplicate artifacts with an enforcer rule.
- Never mix forks and official jars in one deployment.
When it happens
Trigger: Nested result mapping with multiple id/contributing columns on both parent and nested rows (both rowKey and parentRowKey update counts > 1) so combineKeys performs rowKey.clone(); clone() throws CloneNotSupportedException.
Common situations: Essentially untriggerable with stock MyBatis (CacheKey.clone() never throws); appears only with modified classpath versions, old forked copies of mybatis on the classpath shadowing the real one, or exotic bytecode transformations.
Related errors
- Unknown statement type: {}
- Unknown execution method for: {name}
- Mapper method '{name}' attempted to return null from a metho
- Mapper method '{name}' has an unsupported return type: {retu
- method {name} needs either a @ResultMap annotation, a @Resul
AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14).
Data as JSON: /api/errors/4348c2a6f8978ddf.
Report an issue: GitHub.