{"record":{"id":"c14a4f24f677c1db","repo":"hibernate/hibernate-orm","slug":"collection-role-is-declared-with-a-raw-type-an","errorCode":null,"errorMessage":"Collection '<role>' is declared with a raw type and has an explicit 'targetEntity'","messagePattern":"Collection '<role>' is declared with a raw type and has an explicit 'targetEntity'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java","lineNumber":1534,"sourceCode":"\t\t\t\tmodelsContext(),\n\t\t\t\tusage -> {\n\t\t\t\t\tif ( result[0] == null\n\t\t\t\t\t\t\t&& nullIfEmpty( usage.graph() ) == null\n\t\t\t\t\t\t\t&& usage.subgraph().length == 0 ) {\n\t\t\t\t\t\tresult[0] = usage;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t);\n\t\treturn result[0];\n\t}\n\n\tTypeDetails getElementType() {\n\t\tif ( isDefault( targetEntity ) ) {\n\t\t\tif ( collectionElementType != null ) {\n\t\t\t\treturn collectionElementType;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new AnnotationException( \"Collection '\" + safeCollectionRole()\n\t\t\t\t\t\t+ \"' is declared with a raw type and has an explicit 'targetEntity'\" );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\treturn targetEntity;\n\t\t}\n\t}\n\n\tSecondPass getSecondPass() {\n\t\treturn new CollectionSecondPass( collection ) {\n\t\t\t@Override\n\t\t\tpublic void secondPass(Map<String, PersistentClass> persistentClasses) {\n\t\t\t\tbindStarToManySecondPass( persistentClasses );\n\t\t\t}\n\t\t};\n\t}\n\n\t/**","sourceCodeStart":1516,"sourceCodeEnd":1552,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java#L1516-L1552","documentation":"Error \"Collection '<role>' is declared with a raw type and has an explicit 'targetEntity'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A collection mapping uses an annotation or annotation combination that Hibernate forbids for collections.","commonSituations":"Collections carrying conflicting ordering/sorting (@Sort* vs @OrderBy/@OrderColumn), misplaced @JoinColumn, or annotations only valid for single-valued associations.","solutions":["Either parameterize the collection with a generic type and drop targetEntity, or keep the raw type with explicit targetEntity, not both."],"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"}