{"record":{"id":"11a525c1a6c697d0","repo":"hibernate/hibernate-orm","slug":"singlestore-does-not-support-altering-primary-key","errorCode":null,"errorMessage":"SingleStore does not support altering primary key.","messagePattern":"SingleStore does not support altering primary key\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SingleStoreDialect.java","lineNumber":1223,"sourceCode":"\tpublic String getAddForeignKeyConstraintString(\n\t\t\tString constraintName,\n\t\t\tString[] foreignKey,\n\t\t\tString referencedTable,\n\t\t\tString[] primaryKey,\n\t\t\tboolean referencesPrimaryKey) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\"SingleStore does not support foreign keys and referential integrity.\" );\n\t}\n\n\t@Override\n\tpublic String getAddForeignKeyConstraintString(String constraintName, String foreignKeyDefinition) {\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\"SingleStore does not support foreign keys and referential integrity.\" );\n\t}\n\n\t@Override\n\tpublic String getAddPrimaryKeyConstraintString(String constraintName) {\n\t\tthrow new UnsupportedOperationException( \"SingleStore does not support altering primary key.\" );\n\t}\n\n\t@Override\n\tpublic String getWriteLockString(String aliases, Timeout timeout) {\n\t\treturn getForUpdateString( aliases );\n\t}\n\n\t@Override\n\tpublic String getWriteLockString(String aliases, int timeout) {\n\t\treturn getForUpdateString( aliases );\n\t}\n\n\t@Override\n\tpublic String getForUpdateSkipLockedString(String aliases) {\n\t\treturn getForUpdateString();\n\t}\n\n\t@Override","sourceCodeStart":1205,"sourceCodeEnd":1241,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SingleStoreDialect.java#L1205-L1241","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before - auto-update attempts ALTER TABLE ADD PRIMARY KEY (throws)\n// hibernate.hbm2ddl.auto = update\n\n// after - versioned migration rebuilds the table\n// hibernate.hbm2ddl.auto = none\n// V3__orders_pk.sql:\n// CREATE TABLE orders_new(id ... PRIMARY KEY, ...);\n// INSERT INTO orders_new SELECT * FROM orders;\n// DROP TABLE orders;\n// RENAME TABLE orders_new TO orders;","handlingStrategy":"validation","validationCode":"if (dialect instanceof SingleStoreDialect) {\n    throw new IllegalStateException(\n        'SingleStore cannot ALTER a primary key; generate a table rebuild migration instead');\n}\nddl.add(dialect.getAddPrimaryKeyConstraintString(constraintName));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hibernate","singlestore","dialect","primary-key","schema-migration","ddl"],"backgroundTag":"schema-migration-unsupported-constraint","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}