{"record":{"id":"a0951617e42d36c9","repo":"baomidou/mybatis-plus","slug":"cannot-use-both-value-and-name-attribute-in-th","errorCode":null,"errorMessage":"Cannot use both value() and name() attribute in the @CacheNamespaceRef","messagePattern":"Cannot use both value\\(\\) and name\\(\\) attribute in the @CacheNamespaceRef","errorType":"exception","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisMapperAnnotationBuilder.java","lineNumber":189,"sourceCode":"            return null;\n        }\n        Properties props = new Properties();\n        for (Property property : properties) {\n            props.setProperty(property.name(), PropertyParser.parse(property.value(), configuration.getVariables()));\n        }\n        return props;\n    }\n\n    private void parseCacheRef() {\n        CacheNamespaceRef cacheDomainRef = type.getAnnotation(CacheNamespaceRef.class);\n        if (cacheDomainRef != null) {\n            Class<?> refType = cacheDomainRef.value();\n            String refName = cacheDomainRef.name();\n            if (refType == void.class && refName.isEmpty()) {\n                throw new BuilderException(\"Should be specified either value() or name() attribute in the @CacheNamespaceRef\");\n            }\n            if (refType != void.class && !refName.isEmpty()) {\n                throw new BuilderException(\"Cannot use both value() and name() attribute in the @CacheNamespaceRef\");\n            }\n            String namespace = refType != void.class ? refType.getName() : refName;\n            try {\n                assistant.useCacheRef(namespace);\n            } catch (IncompleteElementException e) {\n                configuration.addIncompleteCacheRef(new CacheRefResolver(assistant, namespace));\n            }\n        }\n    }\n\n    private String parseResultMap(Method method) {\n        Class<?> returnType = getReturnType(method, type);\n        Arg[] args = method.getAnnotationsByType(Arg.class);\n        Result[] results = method.getAnnotationsByType(Result.class);\n        TypeDiscriminator typeDiscriminator = method.getAnnotation(TypeDiscriminator.class);\n        String resultMapId = generateResultMapName(method);\n        applyResultMap(resultMapId, returnType, args, results, typeDiscriminator);\n        return resultMapId;","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisMapperAnnotationBuilder.java#L171-L207","documentation":"Thrown while parsing a mapper interface when @CacheNamespaceRef specifies both value() and name(). These two attributes are alternative ways to identify the referenced cache namespace (class vs string), and supplying both is contradictory, so the builder rejects it to avoid guessing which one wins.","triggerScenarios":"Declaring @CacheNamespaceRef(value = UserMapper.class, name = \"com.example.UserMapper\") on a mapper interface; refType != void.class and refName is non-empty in parseCacheRef().","commonSituations":"Refactoring from name-based to class-based references and leaving both attributes populated; IDE generating stub attribute values when adding the annotation.","solutions":["Keep exactly one attribute: prefer the type-safe value() form @CacheNamespaceRef(UserMapper.class).","If the target is not a compile-time-visible class (e.g. XML-only namespace), keep only name() and delete value().","Re-run the application to confirm mapper parsing succeeds."],"exampleFix":"// before\n@CacheNamespaceRef(value = UserMapper.class, name = \"com.example.UserMapper\")\npublic interface OrderMapper extends BaseMapper<Order> {}\n\n// after\n@CacheNamespaceRef(UserMapper.class)\npublic interface OrderMapper extends BaseMapper<Order> {}","handlingStrategy":"validation","validationCode":"org.apache.ibatis.annotations.CacheNamespaceRef ref = mapper.getAnnotation(org.apache.ibatis.annotations.CacheNamespaceRef.class);\nif (ref != null && ref.value() != void.class && !ref.name().isEmpty()) {\n    throw new IllegalStateException(mapper + \" sets both value() and name() in @CacheNamespaceRef\");\n}","typeGuard":null,"tryCatchPattern":"Catch BuilderException at parse time; message identifies the mapper — remove one attribute and rebuild.","preventionTips":["Standardize on the class-based value() form across the codebase.","When refactoring to name-based refs, delete value() in the same commit."],"tags":["mybatis","mybatis-plus","annotation","cache","configuration"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}