hibernate/hibernate-orm · error · MappingException
dialect does not support sequences
Error message
dialect does not support sequences
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/dialect/sequence/NoSequenceSupport.java:31
* @author Gavin King
*/
public class NoSequenceSupport implements SequenceSupport {
public static final SequenceSupport INSTANCE = new NoSequenceSupport();
@Override
public boolean supportsSequences() {
return false;
}
@Override
public boolean supportsPooledSequences() {
return false;
}
@Override
public String getSequenceNextValString(String sequenceName) throws MappingException {
throw new MappingException("dialect does not support sequences");
}
@Override
public String getSequenceNextValString(String sequenceName, int increment) throws MappingException {
throw new MappingException("dialect does not support sequences");
}
@Override
public String getSelectSequenceNextValString(String sequenceName) throws MappingException {
throw new MappingException("dialect does not support sequences");
}
@Override
public String[] getCreateSequenceStrings(String sequenceName, int initialValue, int incrementSize, String options)
throws MappingException {
throw new MappingException( "dialect does not support sequences" );
}
View on GitHub (pinned to fad1729dce)
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
Example fix
// before (MySQL: no sequences -> MappingException) @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "order_seq") @SequenceGenerator(name = "order_seq", sequenceName = "order_seq", allocationSize = 50) private Long id; // after @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;
Defensive patterns
Strategy: fallback
Validate before calling
if (!sessionFactory.getJdbcServices().getDialect().getSequenceSupport().supportsSequences()) {
// configure IDENTITY/TABLE/UUID generation instead of sequences
} Type guard
static boolean dialectSupportsSequences(SessionFactory sf) {
return sf.getJdbcServices().getDialect().getSequenceSupport().supportsSequences();
} Try / catch
try {
em.persist(new Order());
} catch (MappingException e) {
if ("dialect does not support sequences".equals(e.getMessage())) {
// generator/dialect mismatch: switch the @GeneratedValue strategy for this database
}
throw e;
} Prevention
- 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)
When it happens
Trigger: @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.
Common situations: 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.
Related errors
- ${getClass().getName()} does not support identity key genera
- Null id generated for entity '%s'
- Dialect does not support structured array types: ${dialectCl
- Database does not support user-defined types (remove '@Struc
- unknown type: {sqlTypeCode}
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/5f9091bb5d6ff6f6.
Report an issue: GitHub.