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

  1. Switch the generator to one the database supports: GenerationType.IDENTITY (MySQL auto_increment), GenerationType.TABLE, or a UUID/uuid-hex generator
  2. Remove @SequenceGenerator / GenericGenerator declarations that force sequence usage
  3. If the database actually supports sequences (e.g. MariaDB 10.3+), use the correct dialect so getSequenceSupport() reports real support
  4. 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

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


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/5f9091bb5d6ff6f6. Report an issue: GitHub.