{"record":{"id":"59b44b69e6234c10","repo":"hibernate/hibernate-orm","slug":"any-name-s-mapping-needs-to-specify-2-or-mo","errorCode":null,"errorMessage":"<any name=\"%s\" /> mapping needs to specify 2 or more columns","messagePattern":"<any name=\"(.+?)\" /> mapping needs to specify 2 or more columns","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceAnyImpl.java","lineNumber":90,"sourceCode":"\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic String getSourceName() {\n\t\t\t\t\t\treturn jaxbAnyMapping.getName();\n\t\t\t\t\t}\n\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic List getColumnOrFormulaElements() {\n\t\t\t\t\t\treturn jaxbAnyMapping.getColumn();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t);\n\n\t\t// the list of relational values should contain 2 or more values:\n\t\t//\t\t* the first represents the discriminator\n\t\t//\t\t* the rest represent the fk\n\n\t\tif ( relationalValueSources.size() < 2 ) {\n\t\t\tthrow new MappingException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\tLocale.ENGLISH,\n\t\t\t\t\t\t\t\"<any name=\\\"%s\\\" /> mapping needs to specify 2 or more columns\",\n\t\t\t\t\t\t\tjaxbAnyMapping.getName()\n\t\t\t\t\t),\n\t\t\t\t\torigin()\n\t\t\t);\n\t\t}\n\n\t\tthis.discriminatorSource = new AnyDiscriminatorSource() {\n\t\t\tprivate final HibernateTypeSource typeSource = new HibernateTypeSourceImpl( jaxbAnyMapping.getMetaType() );\n\t\t\tprivate final RelationalValueSource relationalValueSource = relationalValueSources.get( 0 );\n\t\t\tprivate final Map<String,String> valueMappings = new HashMap<>();\n\t\t\t{\n\t\t\t\tfor ( JaxbHbmAnyValueMappingType valueMapping : jaxbAnyMapping.getMetaValue() ) {\n\t\t\t\t\tvalueMappings.put(\n\t\t\t\t\t\t\tvalueMapping.getValue(),\n\t\t\t\t\t\t\tsourceMappingDocument.qualifyClassName( valueMapping.getClazz() )","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/SingularAttributeSourceAnyImpl.java#L72-L108","documentation":"<any/> maps a polymorphic entity reference on a singular attribute and needs at least two relational values: column #1 is the discriminator (resolved through meta-type to an entity name) and the remaining column(s) are the foreign key. SingularAttributeSourceAnyImpl aborts bootstrap when fewer than two column definitions are supplied.","triggerScenarios":"An <any name='owner' meta-type='string' id-type='long'> mapping with zero or one <column> children - e.g. only <column name='owner_id'/> - declared on an entity or component mapping.","commonSituations":"Modeling an interface-typed association and forgetting the discriminator column; converting a <many-to-one> to <any> without altering the table; writing hbm equivalents of @Any annotations and missing one @Column.","solutions":["Map two or more columns: the first is the discriminator matching meta-type values, e.g. <column name='owner_type'/>, followed by the fk, e.g. <column name='owner_id'/>","Add <meta-value .../> entries where discriminator values differ from entity names, and verify meta-type/id-type match the column contents","If the schema has only one column, <any> cannot work - use a plain association or add the discriminator column first"],"exampleFix":"// before\n<any name='owner' meta-type='string' id-type='long'>\n    <column name='owner_id'/>\n</any>\n\n// after\n<any name='owner' meta-type='string' id-type='long'>\n    <column name='owner_type'/>\n    <column name='owner_id'/>\n</any>","handlingStrategy":"validation","validationCode":"// Pre-flight: every <any> must declare >= 2 columns\nvar any = (org.w3c.dom.Element) doc.getElementsByTagName(\"any\").item(0);\nint n = any.getElementsByTagName(\"column\").getLength();\nif (n < 2)\n    throw new IllegalStateException(\"<any name='\" + any.getAttribute(\"name\")\n            + \"'> needs discriminator + fk columns, found \" + n);","typeGuard":null,"tryCatchPattern":"catch (org.hibernate.boot.MappingException e) at Metadata build: the message names the <any> attribute - add the discriminator column first and the fk column(s) after it","preventionTips":["When mapping interface-typed associations, always provision a discriminator column plus fk column(s)","First column = discriminator (meta-type), remaining columns = fk - keep the order","Prefer annotation-based @Any with explicit @Column defs where the two-column need is obvious"],"tags":["hibernate","hbm","any","polymorphism","mapping","orm"],"backgroundTag":"mapping-column-count-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}