pagehelper-org/Mybatis-PageHelper · error · PageException
error initializing helper dialectclass
Error message
error initializing helper dialectclass[${dialectClass}]${message} What it means
Generic failure wrapper in instanceDialect: any exception thrown while resolving (ClassNotFoundException from resloveDialectClass) or instantiating the dialect class (reflection, no-arg constructor, abstract class) is caught and rethrown as a PageException 'error initializing helper dialectclass[<name>]<message>' with the original exception as cause.
Solutions
- Inspect the cause of this PageException — it contains the real ClassNotFound/reflective error.
- Correct the helperDialect value: a built-in alias (mysql, oracle, ...) or an existing fully-qualified class name.
- Add the jar containing the custom dialect to the classpath / fix the package declaration.
- Ensure the class is public, concrete, and has a public no-arg constructor.
Example fix
// before
props.setProperty("helperDialect", "com.myapp.MyDialectV5"); // class not on classpath
// after (built-in alias) or ship the correct class
props.setProperty("helperDialect", "mysql"); Defensive patterns
Strategy: try-catch
Validate before calling
String name = props.getProperty("helperDialect");
if (name != null && name.contains(".")) {
try { Class.forName(name, true, PageHelper.class.getClassLoader()); }
catch (ClassNotFoundException e) { throw new IllegalStateException("dialect class missing: " + name, e); }
} Try / catch
try {
dialect = PageAutoDialect.instanceDialect(dialectClass, props);
} catch (PageException e) {
Throwable cause = e.getCause();
log.error("Failed to init dialect {} : {}", dialectClass, cause == null ? e : cause.getMessage());
throw new ConfigurationException("Fix helperDialect/dialectAlias value: " + dialectClass, e);
} Prevention
- Always inspect the cause chain — this message wraps ClassNotFoundException, InstantiationException, or constructor failures.
- Use built-in dialect aliases where possible to avoid classpath issues entirely.
- Ship custom dialect classes in the same artifact as your config to prevent drift.
- Run an integration test that initializes the interceptor with production properties.
When it happens
Trigger: helperDialect or a dialectAlias value names a class that does not exist or cannot be instantiated: misspelled fully-qualified name, custom dialect class not on classpath, abstract/non-public class, or constructor throwing during newInstance().
Common situations: Typo in helperDialect custom class name; custom dialect jar not included in the deployment; dialect class written for a different PageHelper major version (package com.github.pagehelper.dialect changed); dialect class made abstract after refactor.
Related errors
- Make sure the Dialect implementation class configured by…
- When using PageHelper, the dialect must be an…
- Make sure that the AutoDialect implementation class
- Created Sql Cache [ ] Error
- When you use the PageHelper pagination plugin, you must set…
AI-assisted analysis of pagehelper-org/Mybatis-PageHelper@c692616c5b (2026-09-08).
Data as JSON: /api/errors/32832f9be596314d.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/com/github/pagehelper/page/PageAutoDialect.java:208
* 初始化 helper
*
* @param dialectClass
* @param properties
*/
public static AbstractHelperDialect instanceDialect(String dialectClass, Properties properties) {
AbstractHelperDialect dialect;
if (StringUtil.isEmpty(dialectClass)) {
throw new PageException("When you use the PageHelper pagination plugin, you must set the helper property");
}
try {
Class sqlDialectClass = resloveDialectClass(dialectClass);
if (AbstractHelperDialect.class.isAssignableFrom(sqlDialectClass)) {
dialect = (AbstractHelperDialect) sqlDialectClass.newInstance();
} else {
throw new PageException("When using PageHelper, the dialect must be an implementation class that implements the " + AbstractHelperDialect.class.getCanonicalName() + " interface!");
}
} catch (Exception e) {
throw new PageException("error initializing helper dialectclass[" + dialectClass + "]" + e.getMessage(), e);
}
dialect.setProperties(properties);
return dialect;
}
/**
* 多数据动态获取时,每次需要初始化,还可以运行时指定具体的实现
*
* @param ms
* @param dialectClass 分页实现,必须是 {@link AbstractHelperDialect} 实现类,可以使用当前类中注册的别名,例如 "mysql", "oracle"
*/
public void initDelegateDialect(MappedStatement ms, String dialectClass) {
if (StringUtil.isNotEmpty(dialectClass)) {
AbstractHelperDialect dialect = urlDialectMap.get(dialectClass);
if (dialect == null) {
lock.lock();
try {
if ((dialect = urlDialectMap.get(dialectClass)) == null) {View on GitHub (pinned to c692616c5b)