hibernate/hibernate-orm · error · IllegalStateException

Same column is added more than once with different values fo

Error message

Same column is added more than once with different values for isInsertable

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java:226

	public void addFormula(Formula formula) {
		justAddFormula( formula );
	}

	protected void justAddColumn(Column column) {
		justAddColumn( column, true, true );
	}

	protected void justAddColumn(Column column, boolean insertable, boolean updatable) {
		final int index = columns.indexOf( column );
		if ( index == -1 ) {
			columns.add( column );
			insertability.add( insertable );
			updatability.add( updatable );
		}
		else {
			if ( insertability.get( index ) != insertable ) {
				throw new IllegalStateException( "Same column is added more than once with different values for isInsertable" );
			}
			if ( updatability.get( index ) != updatable ) {
				throw new IllegalStateException( "Same column is added more than once with different values for isUpdatable" );
			}
		}
	}

	protected void justAddFormula(Formula formula) {
		columns.add( formula );
		insertability.add( false );
		updatability.add( false );
	}

	public void sortColumns(int[] originalOrder) {
		if ( columns.size() > 1 ) {
			final var originalColumns = columns.toArray( new Selectable[0] );
			final var originalInsertability = toBooleanArray( insertability );
			final var originalUpdatability = toBooleanArray( updatability );

View on GitHub (pinned to fad1729dce)

Solutions

  1. 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
  2. Search the mapping set for every @Column/@JoinColumn with that name and make the insertable value agree
  3. Drop the redundant mapping of the column entirely

Example fix

// before
@ManyToOne @JoinColumn(name = "user_id")
private User user;
@Column(name = "user_id", insertable = false)
private Long userId; // updatable still true -> flag mismatch

// after
@ManyToOne @JoinColumn(name = "user_id")
private User user;
@Column(name = "user_id", insertable = false, updatable = false)
private Long userId;
Defensive patterns

Strategy: validation

Validate before calling

static void checkConsistentColumnFlags(Class<?> entity) {
    Map<String, String> byColumn = new HashMap<>();
    for (Field f : entity.getDeclaredFields()) {
        JoinColumn jc = f.getAnnotation(JoinColumn.class);
        Column col = f.getAnnotation(Column.class);
        if (jc == null && col == null) continue;
        String name = jc != null ? jc.name() : (!col.name().isEmpty() ? col.name() : f.getName());
        boolean ins = jc != null ? jc.insertable() : col.insertable();
        boolean upd = jc != null ? jc.updatable() : col.updatable();
        String sig = ins + "/" + upd;
        String prev = byColumn.put(name, sig);
        if (prev != null && !prev.equals(sig)) {
            throw new IllegalStateException(entity.getName() + '.' + f.getName() + " -> " + name);
        }
    }
}

Try / catch

try { metadata.buildSessionFactory(); }
catch (IllegalStateException e) {
    if (e.getMessage().contains("isInsertable")) {
        // find both mappings of the column and make insertable agree (usually false on the mirror)
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/3a6659e52aa09181. Report an issue: GitHub.