{"record":{"id":"b36d37ae07d85dfe","repo":"hibernate/hibernate-orm","slug":"no-unique-value","errorCode":null,"errorMessage":"no unique value","messagePattern":"no unique value","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/MetaAttribute.java","lineNumber":38,"sourceCode":"\tpublic MetaAttribute(String name) {\n\t\tthis.name = name;\n\t}\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic java.util.List<String> getValues() {\n\t\treturn Collections.unmodifiableList(values);\n\t}\n\n\tpublic void addValue(String value) {\n\t\tvalues.add(value);\n\t}\n\n\tpublic String getValue() {\n\t\tif ( values.size()!=1 ) {\n\t\t\tthrow new IllegalStateException(\"no unique value\");\n\t\t}\n\t\treturn values.get(0);\n\t}\n\n\tpublic boolean isMultiValued() {\n\t\treturn values.size()>1;\n\t}\n\n\tpublic String toString() {\n\t\treturn \"[\" + name + \"=\" + values + \"]\";\n\t}\n}\n","sourceCodeStart":20,"sourceCodeEnd":51,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/MetaAttribute.java#L20-L51","documentation":"MetaAttribute#getValue throws IllegalStateException when the attribute holds zero or more than one value - only a single-valued meta attribute has a unique value. Meta attributes come from hbm <meta value=\"...\"> elements and may legitimately repeat, so asking for 'the' value is only valid when exactly one exists.","triggerScenarios":"The same <meta attribute=\"...\"> declared multiple times in one mapping element; inheritable meta attributes duplicated across mapping levels; tooling (hbm2java, reverse engineering) reading a single value from a multi-valued attribute; calling getValue() without checking the value count.","commonSituations":"Hand-edited hbm files where meta tags were duplicated by copy-paste; templates emitting the same meta attribute more than once; merging mappings that each carry the same meta attribute.","solutions":["Call isMultiValued() or check getValues().size() before getValue(), or just use getValues() when multiple values are legal.","Deduplicate the <meta> elements in the hbm file so the attribute is single-valued.","Update tooling that assumes uniqueness to handle the value list."],"exampleFix":"// before\nString v = metaAttribute.getValue(); // throws when 0 or 2+ values\n\n// after\nif (metaAttribute.getValues().size() == 1) {\n    String v = metaAttribute.getValue();\n} else {\n    List<String> all = metaAttribute.getValues();\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static Optional<String> uniqueValue(MetaAttribute attr) {\n    return attr.getValues().size() == 1\n            ? Optional.of(attr.getValue())\n            : Optional.empty();\n}","tryCatchPattern":null,"preventionTips":["Prefer getValues() over getValue() unless the mapping schema guarantees exactly one value.","Validate hbm files for duplicate <meta> elements with the same attribute name.","When merging inherited meta attributes, concatenate values instead of assuming uniqueness."],"tags":["hibernate","orm","mapping","meta-attribute","hbm","tooling"],"backgroundTag":"meta-attribute-not-unique","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}