{"record":{"id":"a538c8bea5a68df1","repo":"hibernate/hibernate-orm","slug":"singlestore-does-not-support-foreign-keys-and-refe","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":946,"sourceCode":"\t\t\t\t.replace( \"mm\", \"%i\" )\n\t\t\t\t.replace( \"m\", \"%i\" )\n\n\t\t\t\t//second\n\t\t\t\t.replace( \"ss\", \"%S\" )\n\t\t\t\t.replace( \"s\", \"%S\" )\n\n\t\t\t\t//fractional seconds\n\t\t\t\t.replace( \"SSSSSS\", \"%f\" )\n\t\t\t\t.replace( \"SSSSS\", \"%f\" )\n\t\t\t\t.replace( \"SSSS\", \"%f\" )\n\t\t\t\t.replace( \"SSS\", \"%f\" )\n\t\t\t\t.replace( \"SS\", \"%f\" )\n\t\t\t\t.replace( \"S\", \"%f\" );\n\t}\n\n\t@Override\n\tpublic String getDropForeignKeyString() {\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 getDropUniqueKeyString() {\n\t\treturn \"drop index\";\n\t}\n\n\t@Override\n\tpublic String getAlterColumnTypeString(String columnName, String columnType, String columnDefinition) {\n\t\t// no way to change just the column type, leaving other attributes intact\n\t\treturn \"modify column \" + columnName + \" \" + columnDefinition.trim();\n\t}\n\n\t/**\n\t * SingleStore doesn't support modifying column type on columnstore tables.\n\t * It only supports modifying column type on rowstore table.\n\t */","sourceCodeStart":928,"sourceCodeEnd":964,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/SingleStoreDialect.java#L928-L964","documentation":"SingleStoreDialect.getDropForeignKeyString() always throws because SingleStore (formerly MemSQL) does not support foreign keys or referential integrity at all: there is no DROP CONSTRAINT for FKs to emit. Hibernate's schema tooling hits this method when it tries to drop a foreign key during schema update/drop over mappings that contain associations. This is a hard capability gap of the database, not a dialect bug.","triggerScenarios":"SchemaUpdate/SchemaExport drop or update (hibernate.hbm2ddl.auto=update, or explicit SchemaExport.drop) over mappings containing @ManyToOne/@OneToMany FK constraints on SingleStore; generic DDL utilities that ask every dialect for drop-FK SQL.","commonSituations":"Pointing an application originally written for MySQL at SingleStore; auto-DDL left enabled from a local test profile; CI running drop-and-create cycles against a SingleStore container.","solutions":["Set hibernate.hbm2ddl.auto=none (or validate-only after aligning mappings) and manage DDL with migrations","Annotate associations with @ForeignKey(NO_CONSTRAINT) so schema tooling never generates FK DDL for SingleStore","Enforce referential integrity in the service layer, since SingleStore will not enforce it","In custom tooling, gate drop-FK statements on dialect.dropConstraints() before asking for SQL"],"exampleFix":"// before - association produces FK DDL SingleStore cannot execute\n@ManyToOne\n@JoinColumn(name = 'customer_id')\nprivate Customer customer;\n\n// after - no constraint DDL is generated\n@ManyToOne\n@JoinColumn(name = 'customer_id', foreignKey = @ForeignKey(NO_CONSTRAINT))\nprivate Customer customer;","handlingStrategy":"validation","validationCode":"Dialect dialect = sessionFactory.getJdbcServices().getDialect();\nif (dialect.dropConstraints()) {\n    ddl.add(dialect.getDropForeignKeyString());\n}\n// SingleStore throws from these methods: its dropConstraints()/FK capability is absent,\n// so the FK drop must be skipped entirely","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Annotate all associations with @ForeignKey(NO_CONSTRAINT) when targeting SingleStore","Set hibernate.hbm2ddl.auto to none or validate on SingleStore","Enforce referential integrity in the service layer; SingleStore never will"],"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"}