{"record":{"id":"4af18eb3e094d53e","repo":"baomidou/mybatis-plus","slug":"should-be-specified-either-value-or-name-attri","errorCode":null,"errorMessage":"Should be specified either value() or name() attribute in the @CacheNamespaceRef","messagePattern":"Should be specified either value\\(\\) or 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":186,"sourceCode":"\n    private Properties convertToProperties(Property[] properties) {\n        if (properties.length == 0) {\n            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);","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisMapperAnnotationBuilder.java#L168-L204","documentation":"Thrown while parsing a mapper interface when @CacheNamespaceRef is present but neither of its attributes is set. The annotation needs either value() (a class whose cache to share) or name() (a namespace name); when value() is still the default void.class and name() is the empty string, the builder cannot determine the referenced cache and rejects the configuration.","triggerScenarios":"Declaring @CacheNamespaceRef with no attributes on a mapper interface: @CacheNamespaceRef public interface UserMapper {...}, leaving value() = void.class and name() = \"\".","commonSituations":"Copy-pasting a @CacheNamespaceRef declaration from another mapper and deleting the target class; IDE auto-importing CacheNamespaceRef while adding an unrelated annotation; upgrading MyBatis/MyBatis-Plus versions where previously lenient parsing now validates attributes.","solutions":["Set value() to the mapper class whose cache to reference: @CacheNamespaceRef(UserMapper.class).","Or set name() to the target namespace string: @CacheNamespaceRef(name = \"com.example.UserMapper\").","If shared caching was not intended, remove the @CacheNamespaceRef annotation entirely."],"exampleFix":"// before\n@CacheNamespaceRef\npublic interface OrderMapper extends BaseMapper<Order> {}\n\n// after\n@CacheNamespaceRef(UserMapper.class)\npublic interface OrderMapper extends BaseMapper<Order> {}","handlingStrategy":"validation","validationCode":"// reflectively validate @CacheNamespaceRef before factory build\nClass<?> mapper = com.example.mapper.OrderMapper.class;\norg.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 + \" has @CacheNamespaceRef without value() or name()\");\n}","typeGuard":null,"tryCatchPattern":"Catch BuilderException during configuration parse; message names the mapper — fix the annotation and restart. Not retryable.","preventionTips":["Always write @CacheNamespaceRef(SomeMapper.class) — never bare.","Lint mapper annotations in code review."],"tags":["mybatis","mybatis-plus","annotation","cache","configuration"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}