{"record":{"id":"5f9091bb5d6ff6f6","repo":"hibernate/hibernate-orm","slug":"dialect-does-not-support-sequences","errorCode":null,"errorMessage":"dialect does not support sequences","messagePattern":"dialect does not support sequences","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/sequence/NoSequenceSupport.java","lineNumber":31,"sourceCode":" * @author Gavin King\n */\npublic class NoSequenceSupport implements SequenceSupport {\n\n\tpublic static final SequenceSupport INSTANCE = new NoSequenceSupport();\n\n\t@Override\n\tpublic boolean supportsSequences() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean supportsPooledSequences() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic String getSequenceNextValString(String sequenceName) throws MappingException {\n\t\tthrow new MappingException(\"dialect does not support sequences\");\n\t}\n\n\t@Override\n\tpublic String getSequenceNextValString(String sequenceName, int increment) throws MappingException {\n\t\tthrow new MappingException(\"dialect does not support sequences\");\n\t}\n\n\t@Override\n\tpublic String getSelectSequenceNextValString(String sequenceName) throws MappingException {\n\t\tthrow new MappingException(\"dialect does not support sequences\");\n\t}\n\n\t@Override\n\tpublic String[] getCreateSequenceStrings(String sequenceName, int initialValue, int incrementSize, String options)\n\t\t\tthrows MappingException {\n\t\tthrow new MappingException( \"dialect does not support sequences\" );\n\t}\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/sequence/NoSequenceSupport.java#L13-L49","documentation":"NoSequenceSupport is the SequenceSupport Hibernate installs for dialects without database sequences (default Dialect.getSequenceSupport(), MySQL, DB2 for i without sequence support). getSequenceNextValString(sequenceName) is called to build the 'select nextval' SQL used by sequence-based id generators, and on these dialects it throws MappingException('dialect does not support sequences') - typically surfaced at bootstrap when the mapping is validated, or at the first insert that needs an id.","triggerScenarios":"@GeneratedValue(strategy = GenerationType.SEQUENCE) (or an explicit sequence generator) on an entity mapped to MySQL (MySQLDialect.getSequenceSupport returns NoSequenceSupport) or DB2iDialect when sequences are unavailable; calling dialect.getSequenceNextValString(...) directly in custom schema/id tooling; a pooled optimizer resolving to the sequence supporter.","commonSituations":"Entity models developed on PostgreSQL/Oracle reused against MySQL; ' AUTO' strategies that resolve to sequences on some databases being forced with an explicit SEQUENCE strategy; DB2 for i editions/timestamps where sequence support is conditional; migration between databases without changing generator strategies.","solutions":["Switch the generator to one the database supports: GenerationType.IDENTITY (MySQL auto_increment), GenerationType.TABLE, or a UUID/uuid-hex generator","Remove @SequenceGenerator / GenericGenerator declarations that force sequence usage","If the database actually supports sequences (e.g. MariaDB 10.3+), use the correct dialect so getSequenceSupport() reports real support","Verify with sessionFactory.getJdbcServices().getDialect().getSequenceSupport().supportsSequences() during startup smoke tests"],"exampleFix":"// before (MySQL: no sequences -> MappingException)\n@Id\n@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = \"order_seq\")\n@SequenceGenerator(name = \"order_seq\", sequenceName = \"order_seq\", allocationSize = 50)\nprivate Long id;\n\n// after\n@Id\n@GeneratedValue(strategy = GenerationType.IDENTITY)\nprivate Long id;","handlingStrategy":"fallback","validationCode":"if (!sessionFactory.getJdbcServices().getDialect().getSequenceSupport().supportsSequences()) {\n    // configure IDENTITY/TABLE/UUID generation instead of sequences\n}","typeGuard":"static boolean dialectSupportsSequences(SessionFactory sf) {\n    return sf.getJdbcServices().getDialect().getSequenceSupport().supportsSequences();\n}","tryCatchPattern":"try {\n    em.persist(new Order());\n} catch (MappingException e) {\n    if (\"dialect does not support sequences\".equals(e.getMessage())) {\n        // generator/dialect mismatch: switch the @GeneratedValue strategy for this database\n    }\n    throw e;\n}","preventionTips":["Choose IDENTITY (MySQL), TABLE, or UUID generators for portable entity models","Validate mappings against every target dialect at bootstrap in CI","Do not force GenerationType.SEQUENCE in models shared across databases","Confirm the dialect matches the real database (MariaDB 10.3+ has sequences; MySQL does not)"],"tags":["sequence","id-generation","dialect","mapping","hibernate"],"backgroundTag":"sequence-not-supported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}