{"record":{"id":"3a6659e52aa09181","repo":"hibernate/hibernate-orm","slug":"same-column-is-added-more-than-once-with-different","errorCode":null,"errorMessage":"Same column is added more than once with different values for isInsertable","messagePattern":"Same column is added more than once with different values for isInsertable","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java","lineNumber":226,"sourceCode":"\n\tpublic void addFormula(Formula formula) {\n\t\tjustAddFormula( formula );\n\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 );","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java#L208-L244","documentation":"The same Column was added to a SimpleValue twice with different insertable flags. justAddColumn() tolerates re-adding a column only when the flags match; a mismatch means two mappings claim the same column with contradictory insert behavior (one insertable, one not), which Hibernate cannot honor, so it throws IllegalStateException.","triggerScenarios":"A @ManyToOne @JoinColumn plus a basic @Column using the same name where only one side is marked insertable=false; @AttributeOverride reusing an existing column with different flags; join-table columns mapped twice with different insertable settings.","commonSituations":"Mapping both the FK association and its raw id column on one entity (very common); overriding embeddable columns onto existing columns; inheritance overriding columns with different flags.","solutions":["Pick one owner for the column: keep the association writable and mark the mirror id column @Column(insertable = false, updatable = false), or the reverse, consistently","Search the mapping set for every @Column/@JoinColumn with that name and make the insertable value agree","Drop the redundant mapping of the column entirely"],"exampleFix":"// before\n@ManyToOne @JoinColumn(name = \"user_id\")\nprivate User user;\n@Column(name = \"user_id\", insertable = false)\nprivate Long userId; // updatable still true -> flag mismatch\n\n// after\n@ManyToOne @JoinColumn(name = \"user_id\")\nprivate User user;\n@Column(name = \"user_id\", insertable = false, updatable = false)\nprivate Long userId;","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(\"isInsertable\")) {\n        // find both mappings of the column and make insertable agree (usually false on the mirror)\n    }\n    throw e;\n}","preventionTips":["Adopt one pattern per entity: writable association plus read-only mirror column (insertable=false, updatable=false)","Never map one physical column through two independently writable paths","Review column flag consistency when adding @AttributeOverride"],"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"}