hibernate/hibernate-orm · error · UnsupportedOperationException

SingleStore does not support altering primary key.

Error message

SingleStore does not support altering primary key.

What it means

SingleStoreDialect.getAddPrimaryKeyConstraintString(...) always throws because SingleStore does not support altering a primary key with ALTER TABLE ADD PRIMARY KEY: the key must be declared in the CREATE TABLE statement. Hibernate's schema tooling hits this method when it tries to reconcile a primary key after the table exists - typically an id mapping was added or changed and hbm2ddl update runs. The fix is structural: rebuild the table with the key inline.

Source

Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SingleStoreDialect.java:1223

	public String getAddForeignKeyConstraintString(
			String constraintName,
			String[] foreignKey,
			String referencedTable,
			String[] primaryKey,
			boolean referencesPrimaryKey) {
		throw new UnsupportedOperationException(
				"SingleStore does not support foreign keys and referential integrity." );
	}

	@Override
	public String getAddForeignKeyConstraintString(String constraintName, String foreignKeyDefinition) {
		throw new UnsupportedOperationException(
				"SingleStore does not support foreign keys and referential integrity." );
	}

	@Override
	public String getAddPrimaryKeyConstraintString(String constraintName) {
		throw new UnsupportedOperationException( "SingleStore does not support altering primary key." );
	}

	@Override
	public String getWriteLockString(String aliases, Timeout timeout) {
		return getForUpdateString( aliases );
	}

	@Override
	public String getWriteLockString(String aliases, int timeout) {
		return getForUpdateString( aliases );
	}

	@Override
	public String getForUpdateSkipLockedString(String aliases) {
		return getForUpdateString();
	}

	@Override

View on GitHub (pinned to fad1729dce)

Solutions

  1. Recreate the table with PRIMARY KEY inline in CREATE TABLE (create new, copy, drop, rename) via a migration
  2. Ensure the PK exists from the first CREATE TABLE and keep hibernate.hbm2ddl.auto at none or validate
  3. If a key change is truly needed, use SingleStore-supported ALTER forms (e.g. ALTER TABLE ... ADD UNIQUE ... AS PRIMARY KEY where available) directly in a migration script, never through Hibernate tooling

Example fix

// before - auto-update attempts ALTER TABLE ADD PRIMARY KEY (throws)
// hibernate.hbm2ddl.auto = update

// after - versioned migration rebuilds the table
// hibernate.hbm2ddl.auto = none
// V3__orders_pk.sql:
// CREATE TABLE orders_new(id ... PRIMARY KEY, ...);
// INSERT INTO orders_new SELECT * FROM orders;
// DROP TABLE orders;
// RENAME TABLE orders_new TO orders;
Defensive patterns

Strategy: validation

Validate before calling

if (dialect instanceof SingleStoreDialect) {
    throw new IllegalStateException(
        'SingleStore cannot ALTER a primary key; generate a table rebuild migration instead');
}
ddl.add(dialect.getAddPrimaryKeyConstraintString(constraintName));

Prevention

When it happens

Trigger: Running hbm2ddl update after adding or changing @Id/@EmbeddedId on an entity mapped to an existing SingleStore table; DDL scripts that stage PK creation as a separate ALTER TABLE ADD PRIMARY KEY; custom tooling calling getAddPrimaryKeyConstraintString directly.

Common situations: Evolving identifier mappings on a live SingleStore database; MySQL-oriented create-scripts (where ALTER ADD PK is idiomatic) replayed on SingleStore; CI drop-create cycles that reorder DDL.

Related errors


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