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();
}
@OverrideView on GitHub (pinned to fad1729dce)
Solutions
- Recreate the table with PRIMARY KEY inline in CREATE TABLE (create new, copy, drop, rename) via a migration
- Ensure the PK exists from the first CREATE TABLE and keep hibernate.hbm2ddl.auto at none or validate
- 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
- Define primary keys in CREATE TABLE from the first deployment on SingleStore
- Treat id-mapping changes on SingleStore as table-rebuild migrations
- Do not stage PK creation as ALTER statements in generated DDL
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
- No add primary key syntax supported by SQLiteDialect
- SingleStore does not support foreign keys and referential in
- SingleStore does not support foreign keys and referential in
- Cannot add primary key constraint in Cloud Spanner.
- No drop foreign key syntax supported by SQLiteDialect
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/11a525c1a6c697d0.
Report an issue: GitHub.