{"record":{"id":"d7ecccea756949a3","repo":"mybatis/mybatis-3","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":"src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java","lineNumber":217,"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":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java#L199-L235","documentation":"The sibling check in parseCacheRef(): @CacheNamespaceRef has both value() set (non-void class) and a non-empty name() string. The two attributes are alternative ways to identify the referenced namespace; specifying both is ambiguous and rejected.","triggerScenarios":"@CacheNamespaceRef(value = UserMapper.class, name = \"com.acme.UserMapper\") — both attributes populated.","commonSituations":"Copy-paste or IDE auto-complete filling both; refactoring from name-based to class-based refs without deleting the old attribute.","solutions":["Keep exactly one attribute: either @CacheNamespaceRef(UserMapper.class) or @CacheNamespaceRef(name = \"com.acme.UserMapper\")","Prefer the class form (value) so refactors stay compile-safe"],"exampleFix":"// before\n@CacheNamespaceRef(value = UserMapper.class, name = \"com.acme.UserMapper\")\n// after\n@CacheNamespaceRef(UserMapper.class)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"for (Class<?> mapper : scannedMappers) {\n  CacheNamespaceRef r = mapper.getAnnotation(CacheNamespaceRef.class);\n  if (r != null && r.value() != void.class && !r.name().isEmpty()) {\n    throw new IllegalStateException(mapper + \" sets both value() and name() in @CacheNamespaceRef\");\n  }\n}","tryCatchPattern":null,"preventionTips":["Standardize on the class-based form only; forbid name= in code review","When switching attribute styles, delete the old attribute in the same commit"],"tags":["mybatis","cache","annotation","configuration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}