{"record":{"id":"70760d3fdae0c31f","repo":"hibernate/hibernate-orm","slug":"same-column-is-added-more-than-once-with-different-70760d","errorCode":null,"errorMessage":"Same column is added more than once with different values for isUpdatable","messagePattern":"Same column is added more than once with different values for isUpdatable","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java","lineNumber":229,"sourceCode":"\t}\n\n\tprotected void justAddColumn(Column column) {\n\t\tjustAddColumn( column, true, true );\n\t}\n\n\tprotected void justAddColumn(Column column, boolean insertable, boolean updatable) {\n\t\tfinal int index = columns.indexOf( column );\n\t\tif ( index == -1 ) {\n\t\t\tcolumns.add( column );\n\t\t\tinsertability.add( insertable );\n\t\t\tupdatability.add( updatable );\n\t\t}\n\t\telse {\n\t\t\tif ( insertability.get( index ) != insertable ) {\n\t\t\t\tthrow new IllegalStateException( \"Same column is added more than once with different values for isInsertable\" );\n\t\t\t}\n\t\t\tif ( updatability.get( index ) != updatable ) {\n\t\t\t\tthrow new IllegalStateException( \"Same column is added more than once with different values for isUpdatable\" );\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected void justAddFormula(Formula formula) {\n\t\tcolumns.add( formula );\n\t\tinsertability.add( false );\n\t\tupdatability.add( false );\n\t}\n\n\tpublic void sortColumns(int[] originalOrder) {\n\t\tif ( columns.size() > 1 ) {\n\t\t\tfinal var originalColumns = columns.toArray( new Selectable[0] );\n\t\t\tfinal var originalInsertability = toBooleanArray( insertability );\n\t\t\tfinal var originalUpdatability = toBooleanArray( updatability );\n\t\t\tfor ( int i = 0; i < originalOrder.length; i++ ) {\n\t\t\t\tfinal int originalIndex = originalOrder[i];\n\t\t\t\tfinal var selectable = originalColumns[i];","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java#L211-L247","documentation":"The same column was re-added with conflicting updatable flags: justAddColumn() found the column already present but with a different updatable value, meaning two mappings of one column disagree on whether it participates in UPDATE statements. It is the updatability sibling of the insertable check and throws IllegalStateException for the same reason: contradictory write behavior on a single column.","triggerScenarios":"@JoinColumn(name=..., updatable=false) on one side and a default-updatable @Column with the same name on the other; a read-only association layered over a writable basic column; overrides reintroducing the column with updatable changed.","commonSituations":"Read-only mirror columns for foreign keys; immutable audit columns mapped twice; embeddable overrides with mismatched flags.","solutions":["Make updatable (and insertable) identical everywhere the column is mapped, usually by marking the redundant side insertable=false and updatable=false","Or remove one of the two mappings of the column","For FK+id pairs, keep the association writable and the id column read-only"],"exampleFix":"// before\n@Column(name = \"user_id\")\nprivate Long userId; // insertable=true, updatable=true\n@ManyToOne @JoinColumn(name = \"user_id\", updatable = false)\nprivate User user;  // updatable=false -> mismatch\n\n// after\n@Column(name = \"user_id\", insertable = false, updatable = false)\nprivate Long userId;\n@ManyToOne @JoinColumn(name = \"user_id\")\nprivate User user;","handlingStrategy":"validation","validationCode":"static void checkConsistentColumnFlags(Class<?> entity) {\n    Map<String, String> byColumn = new HashMap<>();\n    for (Field f : entity.getDeclaredFields()) {\n        JoinColumn jc = f.getAnnotation(JoinColumn.class);\n        Column col = f.getAnnotation(Column.class);\n        if (jc == null && col == null) continue;\n        String name = jc != null ? jc.name() : (!col.name().isEmpty() ? col.name() : f.getName());\n        boolean ins = jc != null ? jc.insertable() : col.insertable();\n        boolean upd = jc != null ? jc.updatable() : col.updatable();\n        String sig = ins + \"/\" + upd;\n        String prev = byColumn.put(name, sig);\n        if (prev != null && !prev.equals(sig)) {\n            throw new IllegalStateException(entity.getName() + '.' + f.getName() + \" -> \" + name);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try { metadata.buildSessionFactory(); }\ncatch (IllegalStateException e) {\n    if (e.getMessage().contains(\"isUpdatable\")) {\n        // find both mappings of the column and make updatable agree\n    }\n    throw e;\n}","preventionTips":["Keep insertable and updatable flags identical on every mapping of the same column","Mark mirror id columns insertable=false, updatable=false as a convention","Automate a column-flag consistency check over entities in CI"],"tags":["hibernate","orm","column-mapping","illegal-state","duplicate-column"],"backgroundTag":"duplicate-column-mapping","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}