{"record":{"id":"67b0a74fba3a7bf2","repo":"hibernate/hibernate-orm","slug":"singlestore-does-not-support-foreign-keys-and-refe-67b0a7","errorCode":null,"errorMessage":"SingleStore does not support foreign keys and referential integrity.","messagePattern":"SingleStore does not support foreign keys and referential integrity\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SingleStoreDialect.java","lineNumber":1211,"sourceCode":"\t\treturn NameQualifierSupport.CATALOG;\n\t}\n\n\t@Override\n\tpublic IdentifierHelper buildIdentifierHelper(IdentifierHelperBuilder builder, DatabaseMetaData metadata)\n\t\t\tthrows SQLException {\n\t\tbuilder.setUnquotedCaseStrategy( IdentifierCaseStrategy.MIXED );\n\t\tbuilder.setQuotedCaseStrategy( IdentifierCaseStrategy.MIXED );\n\t\treturn super.buildIdentifierHelper( builder, metadata );\n\t}\n\n\t@Override\n\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}","sourceCodeStart":1193,"sourceCodeEnd":1229,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SingleStoreDialect.java#L1193-L1229","documentation":"SingleStoreDialect.getAddForeignKeyConstraintString(constraintName, foreignKey, referencedTable, primaryKey, referencesPrimaryKey) always throws because SingleStore does not support foreign keys or referential integrity: there is no ALTER TABLE ADD CONSTRAINT ... FOREIGN KEY to emit. Hibernate's schema migrator calls this overload when it must add an FK for a mapped association during hbm2ddl update. Any mapping that lets the tooling reach for FK DDL will fail on SingleStore.","triggerScenarios":"hibernate.hbm2ddl.auto=update running after a new @ManyToOne/@JoinColumn association was added; SchemaExport create/update over mappings with FK-generating associations on SingleStore; DDL utilities that emit add-FK statements per dialect.","commonSituations":"Bringing a MySQL-designed entity model to SingleStore; auto-DDL enabled in a shared test profile; adding relationships during active development against a SingleStore dev database.","solutions":["Mark associations with @ForeignKey(NO_CONSTRAINT) so no FK DDL is generated for SingleStore","Turn off auto-DDL (hibernate.hbm2ddl.auto=none or validate) and manage schema with migrations","Enforce parent/child consistency in the service layer or via ETL checks, since SingleStore will not enforce it","In generated DDL pipelines, skip ALTER TABLE ADD FOREIGN KEY statements when the target is SingleStore"],"exampleFix":"// before - FK DDL generated for the association\n@ManyToOne\n@JoinColumn(name = 'customer_id')\nprivate Customer customer;\n\n// after - no constraint DDL\n@ManyToOne\n@JoinColumn(name = 'customer_id', foreignKey = @ForeignKey(NO_CONSTRAINT))\nprivate Customer customer;","handlingStrategy":"validation","validationCode":"static boolean emitsForeignKeyDdl(Dialect d) {\n    return !(d instanceof SingleStoreDialect);\n}\n\n// in schema generation:\nif (emitsForeignKeyDdl(dialect)) {\n    ddl.add(dialect.getAddForeignKeyConstraintString(...));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use @ForeignKey(NO_CONSTRAINT) on every association in a SingleStore profile","Disable auto-DDL on SingleStore; ship migrations instead","Add a startup mapping scan that fails fast if FK DDL would be generated for SingleStore"],"tags":["hibernate","singlestore","dialect","foreign-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"}