{"record":{"id":"4b4722efa0fe10ac","repo":"hibernate/hibernate-orm","slug":"column-mappings-for-property-propertyname-mix-4b4722","errorCode":null,"errorMessage":"Column mappings for property '${propertyName}' mix distinct secondary tables","messagePattern":"Column mappings for property '(.+?)' mix distinct secondary tables","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumns.java","lineNumber":179,"sourceCode":"\t\t\t\tfinal AnnotatedColumn previous = columns.get( currentIndex - 1 );\n\t\t\t\tif ( !current.isFormula() && !previous.isFormula() ) {\n\t\t\t\t\tif ( current.isNullable() != previous.isNullable() ) {\n\t\t\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\t\t\t\"Column mappings for property '\" + propertyName + \"' mix nullable with 'not null'\"\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif ( current.isInsertable() != previous.isInsertable() ) {\n\t\t\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\t\t\t\"Column mappings for property '\" + propertyName + \"' mix insertable with 'insertable=false'\"\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif ( current.isUpdatable() != previous.isUpdatable() ) {\n\t\t\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\t\t\t\"Column mappings for property '\" + propertyName + \"' mix updatable with 'updatable=false'\"\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif ( !current.getExplicitTableName().equals( previous.getExplicitTableName() ) ) {\n\t\t\t\t\t\tthrow new AnnotationException(\n\t\t\t\t\t\t\t\t\"Column mappings for property '\" + propertyName + \"' mix distinct secondary tables\"\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","sourceCodeStart":161,"sourceCodeEnd":188,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumns.java#L161-L188","documentation":"While binding a property that maps several columns, Hibernate found that those columns declare different 'table' attributes, i.e. they would live in distinct secondary tables (@Table/@SecondaryTable joined to the primary). A property's columns must all live in one table, so Hibernate refuses the mapping. Checked in the same consistency pass as nullable/insertable/updatable.","triggerScenarios":"One @Column of the property specifies 'table = \"secondary_a\"' while another specifies 'table = \"secondary_b\"' or no table (primary table); an override changes only one column's table; the property mixes a primary-table column with a secondary-table column.","commonSituations":"Splitting a multi-column type or embeddable across two secondary tables; copy-pasting an @Column from another entity whose class used a different @SecondaryTable name; overriding an embedded mapping in a subclass that defines different secondary tables than the original.","solutions":["Pick ONE table for the property and set the same 'table' attribute on every @Column of that property (or remove the attribute entirely to use the primary table).","Verify the secondary table names match exactly (case-sensitivity under the quoting/naming strategy) with the @SecondaryTable declarations on the entity.","If the columns genuinely must live in different tables, map them as separate properties, each consistent."],"exampleFix":"// before\n@Entity\n@SecondaryTable(name = \"addr\")\nclass Customer {\n    @Columns({\n        @Column(name = \"street\", table = \"addr\"),\n        @Column(name = \"zip\", table = \"customer\") // distinct tables -> error\n    })\n    private Address address;\n}\n\n// after\n@Entity\n@SecondaryTable(name = \"addr\")\nclass Customer {\n    @Columns({\n        @Column(name = \"street\", table = \"addr\"),\n        @Column(name = \"zip\", table = \"addr\") // same secondary table\n    })\n    private Address address;\n}","handlingStrategy":"validation","validationCode":"// Before bootstrap: assert one table per property across its columns\nfor (Field f : cls.getDeclaredFields()) {\n    Column[] cols = f.getAnnotationsByType(Column.class);\n    Set<String> tables = Arrays.stream(cols).map(Column::table).collect(toSet());\n    if (tables.size() > 1) {\n        throw new IllegalStateException(cls.getName() + \".\" + f.getName()\n            + \" spans multiple tables: \" + tables);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    SessionFactory sf = cfg.buildSessionFactory();\n} catch (AnnotationException e) {\n    // 'mix distinct secondary tables' -> check table= attributes on @Column\n    log.error(\"Column/table inconsistency in mapping: {}\", e.getMessage());\n    throw e;\n}","preventionTips":["Declare each property wholly in one table; never split a multi-column property across secondary tables.","Keep a naming constant for secondary table names so @Column(table=...) values cannot drift from @SecondaryTable names.","Run a bootstrap test after any @SecondaryTable rename."],"tags":["hibernate","jpa","secondary-table","orm-mapping","boot-time"],"backgroundTag":"secondary-table-mapping-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}