{"record":{"id":"527a8374f94a3264","repo":"hibernate/hibernate-orm","slug":"referenced-field-fieldname-of-class-classn-527a83","errorCode":null,"errorMessage":"Referenced field '${fieldName}' of class '${className}' is not assignable to '${javaTypeName}'","messagePattern":"Referenced field '(.+?)' of class '(.+?)' is not assignable to '(.+?)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java","lineNumber":395,"sourceCode":"\t\t\t\t\t\t.resolveDescriptor( referencedField.getType() );\n\t\t\t}\n\t\t}\n\t\tcatch (NoSuchFieldException e) {\n\t\t\t// ignore\n\t\t}\n\t\treturn null;\n\t}\n\n\t@Override\n\tpublic <E> E getJavaConstant(String className, String fieldName, Class<E> javaTypeClass) {\n\t\ttry {\n\t\t\tfinal var referencedField = getJavaField( className, fieldName );\n\t\t\tif ( referencedField == null ) {\n\t\t\t\tthrow new IllegalArgumentException( \"Referenced field '\" + fieldName\n\t\t\t\t\t\t+ \"' of class '\" + className + \"' does not exist\" );\n\t\t\t}\n\t\t\tif ( !javaTypeClass.isAssignableFrom( canonicalize( referencedField.getType() ) ) ) {\n\t\t\t\tthrow new IllegalArgumentException( \"Referenced field '\" + fieldName\n\t\t\t\t\t\t+ \"' of class '\" + className\n\t\t\t\t\t\t+ \"' is not assignable to '\" + javaTypeClass.getTypeName() + \"'\" );\n\t\t\t}\n\t\t\treturn javaTypeClass.cast( referencedField.get( null) );\n\t\t}\n\t\tcatch (NoSuchFieldException | IllegalAccessException e) {\n\t\t\tthrow new RuntimeException( e );\n\t\t}\n\t}\n\n\tprivate Field getJavaField(String className, String fieldName) throws NoSuchFieldException {\n\t\tfinal Class<?> namedClass = classLoaderService.classForName( className );\n\t\treturn namedClass == null ? null : namedClass.getDeclaredField( fieldName );\n\t}\n\n\t@Override\n\tpublic void addNamedEntityGraph(String graphName, RootGraphImplementor<?> rootGraph) {\n\t\tfinal var old = entityGraphMap.put( graphName, rootGraph.makeCopy( false, graphName ) );","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java#L377-L413","documentation":"Error \"Referenced field '${fieldName}' of class '${className}' is not assignable to '${javaTypeName}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a referenced field exists but its type is not assignable to the expected Java type of the attribute.","commonSituations":"See trigger scenarios.","solutions":["Change the referenced field's type to one assignable to the expected Java type, or fix the expected type in the mapping."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}