hibernate/hibernate-orm · error · IllegalArgumentException

Referenced field ' ' of class ' ' is not assignable to

Error message

Referenced field '${fieldName}' of class '${className}' is not assignable to '${javaTypeName}'

What it means

Thrown by getJavaConstant after the field was located via reflection: javaTypeClass.isAssignableFrom(canonicalize(field.getType())) failed, i.e. the declared type of the referenced constant field is not compatible with the expected Java type the caller requested. This is a type-compatibility guard on the resolved field; the faulty input is the (className, fieldName, javaTypeClass) combination where the field's actual type is incompatible.

Solutions

  1. Change the referenced field's type to one assignable to the expected Java type, or fix the expected type in the mapping.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown when a referenced field exists but its type is not assignable to the expected Java type of the attribute.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java:395

						.resolveDescriptor( referencedField.getType() );
			}
		}
		catch (NoSuchFieldException e) {
			// ignore
		}
		return null;
	}

	@Override
	public <E> E getJavaConstant(String className, String fieldName, Class<E> javaTypeClass) {
		try {
			final var referencedField = getJavaField( className, fieldName );
			if ( referencedField == null ) {
				throw new IllegalArgumentException( "Referenced field '" + fieldName
						+ "' of class '" + className + "' does not exist" );
			}
			if ( !javaTypeClass.isAssignableFrom( canonicalize( referencedField.getType() ) ) ) {
				throw new IllegalArgumentException( "Referenced field '" + fieldName
						+ "' of class '" + className
						+ "' is not assignable to '" + javaTypeClass.getTypeName() + "'" );
			}
			return javaTypeClass.cast( referencedField.get( null) );
		}
		catch (NoSuchFieldException | IllegalAccessException e) {
			throw new RuntimeException( e );
		}
	}

	private Field getJavaField(String className, String fieldName) throws NoSuchFieldException {
		final Class<?> namedClass = classLoaderService.classForName( className );
		return namedClass == null ? null : namedClass.getDeclaredField( fieldName );
	}

	@Override
	public void addNamedEntityGraph(String graphName, RootGraphImplementor<?> rootGraph) {
		final var old = entityGraphMap.put( graphName, rootGraph.makeCopy( false, graphName ) );

View on GitHub (pinned to fad1729dce)