{"record":{"id":"896afceeabb3579b","repo":"hibernate/hibernate-orm","slug":"name-is-not-a-mapattribute-attributeclass","errorCode":null,"errorMessage":"${name} is not a MapAttribute: ${attributeClass}","messagePattern":"(.+?) is not a MapAttribute: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java","lineNumber":644,"sourceCode":"\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Map attributes\n\n\t@Override\n\t@SuppressWarnings(\"unchecked\")\n\t@Nonnull\n\tpublic MapPersistentAttribute<? super J, ?, ?> getMap(@Nonnull String name) {\n\t\tfinal var attribute = findPluralAttribute( name );\n\t\tbasicMapCheck( attribute, name );\n\t\tassert attribute != null;\n\t\treturn (MapPersistentAttribute<? super J, ?, ?>) attribute;\n\t}\n\n\tprivate void basicMapCheck(PluralAttribute<? super J, ?, ?> attribute, String name) {\n\t\tcheckNotNull( \"MapAttribute\", attribute, name );\n\t\tif ( ! MapAttribute.class.isAssignableFrom( attribute.getClass() ) ) {\n\t\t\tthrow new IllegalArgumentException( name + \" is not a MapAttribute: \" + attribute.getClass() );\n\t\t}\n\t}\n\n\t@Override\n\t@SuppressWarnings(\"unchecked\")\n\t@Nonnull\n\tpublic MapPersistentAttribute<J, ?, ?> getDeclaredMap(@Nonnull String name) {\n\t\tfinal var attribute = findDeclaredPluralAttribute( name );\n\t\tbasicMapCheck( attribute, name );\n\t\tassert attribute != null;\n\t\treturn (MapPersistentAttribute<J, ?, ?>) attribute;\n\t}\n\n\t@Override\n\t@SuppressWarnings(\"unchecked\")\n\t@Nonnull\n\tpublic <K, V> MapAttribute<? super J, K, V> getMap(\n\t\t\t@Nonnull String name,","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractManagedType.java#L626-L662","documentation":"getMap(name)/getDeclaredMap(name) found the attribute but its class is not a MapAttribute implementation — the field is actually a Set, List, or bag. The actual attribute class is included in the message.","triggerScenarios":"Calling getMap(\"translations\") when translations is declared as Set<Translation> or List<Translation>. Map semantics require java.util.Map<K,V> (or a Hibernate-specific map mapping) on the entity.","commonSituations":"Refactoring a Map field to a collection of wrapper embeddables without updating metamodel code; expecting getMap to work on @ElementCollection(targetClass=...) list forms.","solutions":["Use getList/getSet/getCollection per the real declaration","Declare the field as Map<K,V> (e.g. @ElementCollection Map<String,String> labels) when map semantics are wanted","Use the message's attributeClass to identify the actual attribute implementation"],"exampleFix":"// before\nMapPersistentAttribute<Article, String, String> t = articleType.getMap(\"translations\"); // Set field -> throws\n\n// after\nSetPersistentAttribute<Article, Translation> t = articleType.getSet(\"translations\");\n// or change field to Map<String,String> translations;","handlingStrategy":"type-guard","validationCode":"var attr = StreamSupport.stream(type.getAttributes().spliterator(), false)\n        .filter(a -> a.getName().equals(name)).findFirst().orElse(null);\nif (!(attr instanceof javax.persistence.metamodel.MapAttribute)) {\n    throw new IllegalArgumentException(name + \" is not a Map on \" + type.getTypeName());\n}","typeGuard":"static boolean isMapAttr(ManagedType<?> type, String name) {\n    for (Attribute<?,?> a : type.getAttributes()) {\n        if (a.getName().equals(name) && a instanceof javax.persistence.metamodel.MapAttribute) return true;\n    }\n    return false;\n}","tryCatchPattern":"try {\n    return type.getMap(name);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"is not a MapAttribute\")) {\n        // real kind is Set/List/Bag — inspect e for attributeClass\n        throw e;\n    }\n    throw e;\n}","preventionTips":["Map accessors require Map<K,V> field declarations","For key/value pairs stored as entity lists, model a wrapper entity instead","Let the exception's attributeClass guide the corrected accessor"],"tags":["hibernate","jpa-metamodel","map-attribute","collection-type","type-mismatch"],"backgroundTag":"jpa-metamodel-collection-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}