hibernate/hibernate-orm · error · MappingException

Unable to determine JavaType to use : {}

Error message

Unable to determine JavaType to use : {}

What it means

During bootstrap, BasicValue resolution needs a domain JavaType: either one configured explicitly, or the recommended Java type of the explicitly assigned JdbcType when only @JdbcType/@JdbcTypeCode is present. When both routes yield null, Hibernate cannot build the type and throws this MappingException; the message includes the BasicValue dump identifying the attribute.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/mapping/BasicValue.java:658

		}
	}

	private Resolution<?> resolution(BasicJavaType explicitJavaType, JavaType<?> javaType) {
		final JavaType<?> basicJavaType;
		final JdbcType jdbcType;
		if ( explicitJdbcTypeAccess != null ) {
			final var typeConfiguration = getTypeConfiguration();
			jdbcType = explicitJdbcTypeAccess.apply( typeConfiguration );
			basicJavaType = javaType == null && jdbcType != null
					? jdbcType.getRecommendedJavaType( null, null, typeConfiguration )
					: javaType;
		}
		else {
			jdbcType = null;
			basicJavaType = javaType;
		}
		if ( basicJavaType == null ) {
			throw new MappingException( "Unable to determine JavaType to use : " + this );
		}

		if ( basicJavaType instanceof BasicJavaType<?> castType
				&& ( !basicJavaType.getJavaTypeClass().isEnum() || enumerationStyle == null ) ) {
			final var context = getBuildingContext();
			final var autoAppliedTypeDef = context.getTypeDefinitionRegistry().resolveAutoApplied( castType );
			if ( autoAppliedTypeDef != null ) {
				CORE_LOGGER.trace( "BasicValue resolution matched auto-applied type definition" );
				return autoAppliedTypeDef.resolve( getTypeParameters(), context, this );
			}
		}

		return InferredBasicValueResolver.from(
				explicitJavaType,
				jdbcType,
				resolvedJavaType,
				this::determineReflectedJavaType,
				explicitMutabilityPlanAccess,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add @JavaType on the attribute or register a JavaType for the value class via @JavaTypeRegistration.
  2. If a custom UserType is involved, make returnedClass() return the concrete class.
  3. Give the attribute a concrete declared type instead of Object or a type variable.

Example fix

// before
@JdbcTypeCode(SqlTypes.JSON)
private MyJsonDoc doc; // no JavaType registered for MyJsonDoc

// after
@JavaType(MyJsonDocJavaType.class)
@JdbcTypeCode(SqlTypes.JSON)
private MyJsonDoc doc;
Defensive patterns

Strategy: validation

Try / catch

try {
    SessionFactory sf = configuration.buildSessionFactory();
}
catch ( MappingException e ) {
    // message: Unable to determine JavaType to use : <BasicValue dump>
    // use the dump to find the offending attribute, then add @JavaType/@Type
}

Prevention

When it happens

Trigger: @JdbcTypeCode(SqlTypes.JSON) on a field whose Java type has no registered JavaTypeDescriptor (custom value class without @JavaTypeRegistration); a custom UserType whose returnedClass() returns null; attributes typed Object or erased generics; Serializable-typed fields unresolved after a 5.x-to-6.x migration.

Common situations: Hibernate 6 migration where legacy type definitions no longer resolve; new custom value objects used with @JdbcTypeCode; fields declared with interface types; missing JavaType registrations for wrapper classes.

Related errors


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