{"record":{"id":"bc9941f6a9335b4c","repo":"hibernate/hibernate-orm","slug":"association-role-targets-the-type-typename","errorCode":null,"errorMessage":"Association '<role>' targets the type '<typeName>' which is not an '@Entity' type","messagePattern":"Association '<role>' targets the type '<typeName>' which is not an '@Entity' type","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java","lineNumber":2579,"sourceCode":"\t\t\tClass<T> annotationClass, MemberDetails property, MetadataBuildingContext context) {\n\t\tfinal var fromProperty = property.getDirectAnnotationUsage( annotationClass );\n\t\tif ( fromProperty != null ) {\n\t\t\treturn fromProperty;\n\t\t}\n\t\t// Check the owning entity class hierarchy (class-level annotation propagates to collections)\n\t\tfinal var modelsContext = context.getBootstrapContext().getModelsContext();\n\t\tfinal var fromClass = property.getDeclaringType().getAnnotationUsage( annotationClass, modelsContext );\n\t\treturn fromClass == null ?\n\t\t\t\textractFromPackage( annotationClass, property.getDeclaringType(), context ) :\n\t\t\t\tfromClass;\n\t}\n\n\tprivate void handleUnownedManyToMany(\n\t\t\tTypeDetails elementType,\n\t\t\tPersistentClass collectionEntity,\n\t\t\tboolean isCollectionOfEntities) {\n\t\tif ( !isCollectionOfEntities ) {\n\t\t\tthrow new AnnotationException( \"Association '\" + safeCollectionRole() + \"'\"\n\t\t\t\t\t+ targetEntityMessage( elementType ) );\n\t\t}\n\n\t\tjoinColumns.setManyToManyOwnerSideEntityName( collectionEntity.getEntityName() );\n\t\tfinal var mappedByPropertyValue =\n\t\t\t\tgetMappedByProperty( elementType, collectionEntity )\n\t\t\t\t\t\t.getValue();\n\t\tfinal var table =\n\t\t\t\tmappedByPropertyValue instanceof Collection collectionProperty\n\t\t\t\t\t\t// this is a collection on the other side\n\t\t\t\t\t\t? collectionProperty.getCollectionTable()\n\t\t\t\t\t\t// this is a ToOne with a @JoinTable or a regular property\n\t\t\t\t\t\t: mappedByPropertyValue.getTable();\n\t\tcollection.setCollectionTable( table );\n\n\t\tprocessSoftDeletes();\n\t\tprocessTemporal();\n\t\tprocessAudited();","sourceCodeStart":2561,"sourceCodeEnd":2597,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java#L2561-L2597","documentation":"Error \"Association '<role>' targets the type '<typeName>' which is not an '@Entity' type\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An association or reference targets a type that Hibernate has not mapped as an entity.","commonSituations":"Missing @Entity on the target class, the class not being scanned into the persistence unit, or a typo in the entity name.","solutions":["Annotate the target type with @Entity, or change the association to target an entity type."],"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"}