{"record":{"id":"c20fed553bfe34dd","repo":"pagehelper-org/Mybatis-PageHelper","slug":"created-sql-cache-sqlcacheclass-error","errorCode":null,"errorMessage":"Created Sql Cache [${sqlCacheClass}] Error","messagePattern":"Created Sql Cache \\[(.+?)\\] Error","errorType":"exception","errorClass":"PageException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/github/pagehelper/cache/CacheFactory.java","lineNumber":69,"sourceCode":"                return new GuavaCache<K, V>(properties, prefix);\n            } catch (Throwable t) {\n                return new SimpleCache<K, V>(properties, prefix);\n            }\n        } else {\n            try {\n                Class<? extends Cache> clazz = (Class<? extends Cache>) Class.forName(sqlCacheClass);\n                try {\n                    Constructor<? extends Cache> constructor = clazz.getConstructor(Properties.class, String.class);\n                    return constructor.newInstance(properties, prefix);\n                } catch (Exception e) {\n                    Cache cache = clazz.newInstance();\n                    if (cache instanceof PageProperties) {\n                        ((PageProperties) cache).setProperties(properties);\n                    }\n                    return cache;\n                }\n            } catch (Throwable t) {\n                throw new PageException(\"Created Sql Cache [\" + sqlCacheClass + \"] Error\", t);\n            }\n        }\n    }\n\n}\n","sourceCodeStart":51,"sourceCodeEnd":75,"githubUrl":"https://github.com/pagehelper-org/Mybatis-PageHelper/blob/c692616c5bc95b41aa779b502f991825c8e5acbc/src/main/java/com/github/pagehelper/cache/CacheFactory.java#L51-L75","documentation":"CacheFactory.createCache instantiates the configured sqlCacheClass (e.g. an EhCache or Redis SqlCache implementation). If loading/creating the cache instance throws for any reason (class missing, constructor failure, initialization error), the Throwable is wrapped in a PageException with this message and the original as cause.","triggerScenarios":"Setting the sqlCacheClass plugin property to a class that does not exist on the classpath, cannot be instantiated (no no-arg constructor), or whose setProperties/init throws during PageHelper plugin initialization.","commonSituations":"Using pagehelper-sqlcache (EhCache/Redis) without adding the dependency jar; typo in the fully-qualified class name; cache library config file (ehcache.xml) missing or invalid so the cache constructor fails at startup.","solutions":["Check the cause (PageException.getCause()) for the real error and fix it.","Add the missing cache implementation dependency (e.g. com.github.pagehelper:pagehelper-sqlcache or ehcache/redis client jars).","Verify the sqlCacheClass value is the exact fully-qualified class name.","Validate the cache's own configuration (ehcache.xml / redis connection) loads correctly."],"exampleFix":"// before (pom.xml missing dependency, config: sqlCacheClass=com.github.pagehelper.cache.EhCache)\n// after\n<dependency>\n  <groupId>com.github.pagehelper</groupId>\n  <artifactId>pagehelper-sqlcache</artifactId>\n  <version>1.0.0</version>\n</dependency>","handlingStrategy":"try-catch","validationCode":"String cls = properties.getProperty(\"sqlCacheClass\");\nif (cls != null) {\n    try { Class.forName(cls); } catch (ClassNotFoundException e) {\n        throw new IllegalStateException(\"sqlCacheClass not on classpath: \" + cls, e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    interceptor.setProperties(props);\n} catch (PageException e) {\n    if (e.getCause() != null) log.error(\"sql cache init root cause\", e.getCause());\n    throw e;\n}","preventionTips":["Read PageException.getCause() first — it carries the real cache instantiation error.","Confirm the cache dependency jar (pagehelper-sqlcache / ehcache / redis client) is in the final artifact.","Validate ehcache.xml or redis connection config in a startup smoke test.","Pin PageHelper and cache-module versions together."],"tags":["cache","class-not-found","initialization","java"],"backgroundTag":"class-not-found","analyzedSha":"c692616c5bc95b41aa779b502f991825c8e5acbc","analyzedAt":"2026-09-08T03:50:49.192Z","contentChangedAt":"2026-09-08T03:50:49.192Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}