{"record":{"id":"1f64962b5633b904","repo":"hibernate/hibernate-orm","slug":"plural-attribute-s-s-was-mapped-with-targetent","errorCode":null,"errorMessage":"Plural attribute [%s.%s] was mapped with targetEntity=`%s`, but the attribute is declared as `%s`","messagePattern":"Plural attribute \\[(.+?)\\.(.+?)\\] was mapped with targetEntity=`(.+?)`, but the attribute is declared as `(.+?)`","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java","lineNumber":247,"sourceCode":"\t\t\tManagedMappingType declaringType,\n\t\t\tMappingModelCreationProcess creationProcess) {\n\t\treturn creationProcess.getCreationContext().getBootstrapContext()\n\t\t\t\t.getModelsContext().getClassDetailsRegistry()\n\t\t\t\t.resolveClassDetails( declaringType.getJavaType().getTypeName() );\n\t}\n\n\tprivate static void checkElementType(\n\t\t\tEntityCollectionPart elementPart,\n\t\t\tManagedMappingType declaringType,\n\t\t\tString attributeName,\n\t\t\tMemberDetails attributeMemberDetails) {\n\t\tfinal var elementType =\n\t\t\t\tattributeMemberDetails.getElementType()\n\t\t\t\t\t\t.determineRawClass().toJavaClass();\n\t\tif ( !Object.class.equals( elementType ) ) {\n\t\t\tfinal var targetType = elementPart.getJavaType().getJavaTypeClass();\n\t\t\tif ( !elementType.isAssignableFrom( targetType ) ) {\n\t\t\t\tthrow new MappingException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\tROOT,\n\t\t\t\t\t\t\t\t\"Plural attribute [%s.%s] was mapped with targetEntity=`%s`,\"\n\t\t\t\t\t\t\t\t\t\t+ \" but the attribute is declared as `%s`\",\n\t\t\t\t\t\t\t\tdeclaringType.getNavigableRole().getFullPath(),\n\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\ttargetType.getName(),\n\t\t\t\t\t\t\t\telementType.getName()\n\t\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static @Nullable MemberDetails getMemberDetails(\n\t\t\tString attributeName, PropertyAccess propertyAccess, ClassDetails declaringClassDetails) {\n\t\tfinal var member = propertyAccess.getGetter().getMember();\n\t\tif ( member instanceof Field ) {","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/PluralAttributeMappingImpl.java#L229-L265","documentation":"Error \"Plural attribute [%s.%s] was mapped with targetEntity=`%s`, but the attribute is declared as `%s`\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when @OneToMany(targetEntity=...) names a class that is not assignable to the declared generic element type of the collection.","commonSituations":"See trigger scenarios.","solutions":["Remove targetEntity from the mapping so it matches the declared attribute type, or change targetEntity to the declared element type.","Fix the generic type of the collection attribute to match the intended target entity."],"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"}