{"record":{"id":"85ffe77d7195e26b","repo":"hibernate/hibernate-orm","slug":"attribute-was-neither-a-collection-nor-a-map-e","errorCode":null,"errorMessage":"Attribute was neither a Collection nor a Map : ${erasedType}","messagePattern":"Attribute was neither a Collection nor a Map : (.+?)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/convert/internal/AutoApplicableConverterDescriptorStandardImpl.java","lineNumber":85,"sourceCode":"\t\t\t\t\ttypeArguments( Map.class, collectionMemberType );\n\t\t\tif ( typeArguments.length < 2 ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\telementType = typeArguments[1];\n\t\t}\n\t\telse if ( Collection.class.isAssignableFrom( erasedType ) ) {\n\t\t\tfinal var typeArguments =\n\t\t\t\t\ttypeArguments( Collection.class, collectionMemberType );\n\t\t\tif ( typeArguments.length == 0 ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\telementType = typeArguments[0];\n\t\t}\n\t\telse if ( erasedType.isArray() ) {\n\t\t\telementType = erasedType.componentType();\n\t\t}\n\t\telse {\n\t\t\tthrow new HibernateException( \"Attribute was neither a Collection nor a Map : \" + erasedType);\n\t\t}\n\n\t\treturn isAssignableFrom( linkedConverterDescriptor.getDomainValueResolvedType(),\n\t\t\t\t\t\tcanonicalizePrimitive( elementType ) )\n\t\t\t\t? linkedConverterDescriptor\n\t\t\t\t: null;\n\t}\n\n\t@Override\n\tpublic ConverterDescriptor<?,?> getAutoAppliedConverterDescriptorForMapKey(\n\t\t\tMemberDetails memberDetails,\n\t\t\tMetadataBuildingContext context) {\n\n\t\tfinal var collectionMemberType = actualMemberType( memberDetails );\n\t\tfinal Type keyType;\n\t\tif ( Map.class.isAssignableFrom( erasedType( collectionMemberType ) ) ) {\n\t\t\tfinal var typeArguments =\n\t\t\t\t\ttypeArguments( Map.class, collectionMemberType );","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/convert/internal/AutoApplicableConverterDescriptorStandardImpl.java#L67-L103","documentation":"AutoApplicableConverterDescriptorStandardImpl resolves the element type of an attribute when matching collection auto-apply converters: it handles Map, Collection, and arrays, and throws HibernateException('Attribute was neither a Collection nor a Map : <erasedType>') for anything else. Reaching this branch means a non-standard container type arrived on a path that assumes a real collection.","triggerScenarios":"An attribute whose erased type implements neither java.util.Collection nor java.util.Map and is not an array — e.g. Iterable<T>, Stream<T>, or a custom container implementing only Iterable — while auto-apply converter scanning evaluates it as a collection site.","commonSituations":"Entity fields declared as Iterable for API convenience; custom/guava-style collection wrappers not extending java.util.Collection; code generated from XSDs/prototypes that model multi-valued fields as generic Iterables.","solutions":["Declare multi-valued fields as List, Set, Collection, Map, or an array instead of Iterable/custom containers","If a custom container is required, make it implement java.util.Collection","Avoid auto-apply converters for the element type of such fields; apply conversion explicitly or disable autoApply on the colliding converter","If the field is a plain standard collection and you still hit this, capture a reproducer and report it to Hibernate (HHH) — it would be an internal resolution bug"],"exampleFix":"// before\n@Entity\npublic class Order {\n    private Iterable<OrderLine> lines; // Iterable is not a Collection\n}\n\n// after\n@Entity\npublic class Order {\n    private List<OrderLine> lines;\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isSupportedMultiValuedType(Class<?> c) {\n    return java.util.Map.class.isAssignableFrom(c)\n        || java.util.Collection.class.isAssignableFrom(c)\n        || c.isArray();\n}","tryCatchPattern":"catch (HibernateException e) {\n    if (String.valueOf(e.getMessage()).startsWith(\"Attribute was neither a Collection nor a Map\")) {\n        throw new IllegalStateException(\"Change the field to List/Set/Collection/Map/array - \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Declare entity attributes as standard collection interfaces (List/Set/Map) or arrays, never Iterable","Make custom containers implement java.util.Collection if they must be mapped","Add an ArchUnit rule banning Iterable-typed persistent fields"],"tags":["jpa","attribute-converter","collections","mapping"],"backgroundTag":"unsupported-collection-type","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}