hibernate/hibernate-orm · error · HibernateException

No type mapping for org.hibernate.type.SqlTypes code: %s (%s

Error message

No type mapping for org.hibernate.type.SqlTypes code: %s (%s)

What it means

DdlTypeRegistry.getTypeName(int, Size) resolves the SQL type name for a JDBC type code during DDL generation. If the current dialect registered no DdlType for that code (getDescriptor returns null), Hibernate throws HibernateException 'No type mapping for SqlTypes code: N (NAME)' with both the numeric code and its SqlTypes name - the dialect literally cannot render DDL for that column type.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/type/descriptor/sql/spi/DdlTypeRegistry.java:232

	 * Get the SQL type name for the specified {@link java.sql.Types JDBC type code}
	 * and size, filling in the placemarkers {@code $l}, {@code $p}, and {@code $s}
	 * with the length, precision, and scale determined by the given {@linkplain Size
	 * size object}. The returned type name should be of a SQL type large enough to
	 * accommodate values of the specified size.
	 *
	 * @apiNote Not appropriate for named enum or array types,
	 *          use {@link #getTypeName(int, Size, Type)} instead
	 *
	 * @param typeCode the JDBC type code
	 * @param size an object which determines the length, precision, and scale
	 *
	 * @return the associated type name with the smallest capacity that accommodates
	 *         the given size, if available, and the default type name otherwise
	 */
	private String getTypeName(int typeCode, Size size) {
		final var descriptor = getDescriptor( typeCode );
		if ( descriptor == null ) {
			throw new HibernateException(
					String.format(
							"No type mapping for org.hibernate.type.SqlTypes code: %s (%s)",
							typeCode,
							JdbcTypeNameMapper.getTypeName( typeCode )
					)
			);
		}
		return descriptor.getTypeName( size, null, this );
	}

	/**
	 * Get the SQL type name for the specified {@link java.sql.Types JDBC type code}
	 * and size, filling in the placemarkers {@code $l}, {@code $p}, and {@code $s}
	 * with the length, precision, and scale determined by the given {@linkplain Size
	 * size object}. The returned type name should be of a SQL type large enough to
	 * accommodate values of the specified size.
	 *
	 * @param typeCode the JDBC type code

View on GitHub (pinned to fad1729dce)

Solutions

  1. Change the attribute to a type code your dialect supports (e.g. SqlTypes.VARCHAR / LONG32VARCHAR instead of JSON or UUID)
  2. Upgrade the dialect/DB so the code gets registered (PostgreSQL for JSON, newer MySQL for UUID)
  3. Contribute a DdlType: subclass Dialect (or a bootstrap contributor) and call ddlTypeRegistry.addDescriptor(new DdlTypeImpl(code, "typename", dialect))
  4. Bypass registry rendering with an explicit @Column(columnDefinition = "...")

Example fix

// before - dialect has no JSON DdlType
@Column(name = "payload")
@JdbcTypeCode(SqlTypes.JSON)
private Map<String, Object> payload; // -> 'No type mapping for SqlTypes code: 3001 (JSON)'

// after - explicit column definition bypasses the registry
@Column(name = "payload", columnDefinition = "text")
@JdbcTypeCode(SqlTypes.JSON)
private Map<String, Object> payload;
Defensive patterns

Strategy: fallback

Validate before calling

// CI step: render DDL for the whole model with no target so unmapped type codes fail the build
new SchemaExport().setOutputFile("target/ddl.sql").createOnly(EnumSet.of(TargetType.SCRIPT), metadata);
// throws HibernateException('No type mapping for SqlTypes code: ...') at build time

Prevention

When it happens

Trigger: Schema export/update/validate on a column whose @JdbcTypeCode or resolved JavaType yields a type code the dialect has no descriptor for: SqlTypes.JSON on a dialect without JSON support, SqlTypes.GEOMETRY without spatial setup, SqlTypes.UUID on older MySQL/MariaDB dialects, or a custom JdbcType code nobody contributed to the registry via ddlTypeRegistry.addDescriptor.

Common situations: Switching databases or dialect versions while keeping modern type codes; using custom JdbcType implementations without a matching DdlType contribution; running hbm2ddl against an older DB server than the mappings assume.

Related errors


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