{"record":{"id":"4a4c8cbf498168f3","repo":"baomidou/mybatis-plus","slug":"could-not-find-a-statement-annotation-that-corresp","errorCode":null,"errorMessage":"Could not find a statement annotation that correspond a current database or default statement on method '%s.%s'. Current database id is [%s].","messagePattern":"Could not find a statement annotation that correspond a current database or default statement on method '(.+?)\\.(.+?)'\\. Current database id is \\[(.+?)\\]\\.","errorType":"exception","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisMapperAnnotationBuilder.java","lineNumber":618,"sourceCode":"                                                                                     Collection<Class<? extends Annotation>> targetTypes) {\n        String databaseId = configuration.getDatabaseId();\n        Map<String, AnnotationWrapper> statementAnnotations = targetTypes.stream()\n            .flatMap(x -> Arrays.stream(method.getAnnotationsByType(x))).map(AnnotationWrapper::new)\n            .collect(Collectors.toMap(AnnotationWrapper::getDatabaseId, x -> x, (existing, duplicate) -> {\n                throw new BuilderException(\n                    String.format(\"Detected conflicting annotations '%s' and '%s' on '%s'.\", existing.getAnnotation(),\n                        duplicate.getAnnotation(), method.getDeclaringClass().getName() + \".\" + method.getName()));\n            }));\n        AnnotationWrapper annotationWrapper = null;\n        if (databaseId != null) {\n            annotationWrapper = statementAnnotations.get(databaseId);\n        }\n        if (annotationWrapper == null) {\n            annotationWrapper = statementAnnotations.get(\"\");\n        }\n        if (errorIfNoMatch && annotationWrapper == null && !statementAnnotations.isEmpty()) {\n            // Annotations exist, but there is no matching one for the specified databaseId\n            throw new BuilderException(String.format(\n                \"Could not find a statement annotation that correspond a current database or default statement on method '%s.%s'. Current database id is [%s].\",\n                method.getDeclaringClass().getName(), method.getName(), databaseId));\n        }\n        return Optional.ofNullable(annotationWrapper);\n    }\n\n    public static Class<?> getMethodReturnType(String mapperFqn, String localStatementId) {\n        if (mapperFqn == null || localStatementId == null) {\n            return null;\n        }\n        try {\n            Class<?> mapperClass = Resources.classForName(mapperFqn);\n            for (Method method : mapperClass.getMethods()) {\n                if (method.getName().equals(localStatementId) && canHaveStatement(method)) {\n                    return getReturnType(method, mapperClass);\n                }\n            }\n        } catch (ClassNotFoundException e) {","sourceCodeStart":600,"sourceCodeEnd":636,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisMapperAnnotationBuilder.java#L600-L636","documentation":"Thrown when a mapper method carries statement annotations but none matches the active databaseId. The builder found annotations (statementAnnotations is non-empty), but neither the current databaseId nor the annotation-default (empty string) key is present, and errorIfNoMatch is on, so the method cannot be bound to any statement for this database.","triggerScenarios":"All @Select/@Insert annotations on a method declare databaseId = \"oracle\" while the runtime Configuration.getDatabaseId() returns \"mysql\" (or null with no default-keyed annotation present).","commonSituations":"Running the app against a different database than the annotations target; DatabaseIdProvider not configured so databaseId is null while annotations only have vendor-qualified variants; changing the databaseIdProvider properties without updating mapper annotations.","solutions":["Add a default (no databaseId) @Select variant on the method so a statement always exists regardless of the active database.","Align the DatabaseIdProvider configuration with the databaseId values used in the annotations (verify the value returned for your DataSource).","If multi-DB support is not needed, strip databaseId attributes from the annotations."],"exampleFix":"// before\n@Select(databaseId = \"oracle\", value = \"SELECT 1 FROM dual\")\nint ping();\n\n// after\n@Select(databaseId = \"oracle\", value = \"SELECT 1 FROM dual\")\n@Select(value = \"SELECT 1\")\nint ping();","handlingStrategy":"validation","validationCode":"// ensure every annotated method has a statement matching the active databaseId\nString currentDbId = factory.getConfiguration().getDatabaseId();\nfor (java.lang.reflect.Method m : mapper.getMethods()) {\n    boolean hasDefault = false, hasCurrent = false;\n    for (java.lang.annotation.Annotation a : m.getAnnotations()) {\n        try {\n            String dbId = (String) a.annotationType().getMethod(\"databaseId\").invoke(a);\n            if (dbId == null || dbId.isEmpty()) hasDefault = true;\n            if (currentDbId != null && currentDbId.equals(dbId)) hasCurrent = true;\n        } catch (NoSuchMethodException ignored) { }\n    }\n    // if any statement annotation exists but neither flag set -> will fail\n}","typeGuard":null,"tryCatchPattern":"Catch BuilderException containing 'Could not find a statement annotation'; add a default-keyed annotation variant or fix DatabaseIdProvider settings.","preventionTips":["Always provide a no-databaseId default annotation alongside vendor variants.","Assert the runtime databaseId in a startup check and fail fast with a clear message."],"tags":["mybatis","mybatis-plus","databaseid","annotation","configuration"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}