{"record":{"id":"3055a435eaa42f6e","repo":"hibernate/hibernate-orm","slug":"association-role-is-a-manytoany-and-must-sp","errorCode":null,"errorMessage":"Association '<role>' is a '@ManyToAny' and must specify a '@JoinTable'","messagePattern":"Association '<role>' is a '@ManyToAny' and must specify a '@JoinTable'","errorType":"exception","errorClass":"AnnotationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java","lineNumber":2623,"sourceCode":"\t\t\t\t\t+ \" is an unowned collection and may not be annotated '@Check'\" );\n\t\t}\n\t}\n\n\tprivate void detectManyToManyProblems(\n\t\t\tTypeDetails elementType,\n\t\t\tboolean isCollectionOfEntities,\n\t\t\tboolean isManyToAny) {\n\n\t\tif ( !isCollectionOfEntities) {\n\t\t\tif ( property.hasDirectAnnotationUsage( ManyToMany.class )\n\t\t\t\t\t|| property.hasDirectAnnotationUsage( OneToMany.class ) ) {\n\t\t\t\tthrow new AnnotationException( \"Association '\" + safeCollectionRole() + \"'\"\n\t\t\t\t\t\t+ targetEntityMessage( elementType ) );\n\t\t\t}\n\t\t\telse if (isManyToAny) {\n\t\t\t\tfinal var joinTable = propertyHolder.getJoinTable( property );\n\t\t\t\tif ( joinTable == null ) {\n\t\t\t\t\tthrow new AnnotationException( \"Association '\" + safeCollectionRole()\n\t\t\t\t\t\t\t+ \"' is a '@ManyToAny' and must specify a '@JoinTable'\" );\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tfinal var joinTableAnn = propertyHolder.getJoinTable( property );\n\t\t\t\tif ( joinTableAnn != null && !ArrayHelper.isEmpty( joinTableAnn.inverseJoinColumns() ) ) {\n\t\t\t\t\tthrow new AnnotationException( \"Association '\" + safeCollectionRole()\n\t\t\t\t\t\t\t+ \" has a '@JoinTable' with 'inverseJoinColumns' and\"\n\t\t\t\t\t\t\t+ targetEntityMessage( elementType ) );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic String targetEntityMessage(TypeDetails elementType) {\n\t\tfinal String problem =\n\t\t\t\tisEntity( elementType.determineRawClass() )\n\t\t\t\t\t\t? \" which does not belong to the same persistence unit\"","sourceCodeStart":2605,"sourceCodeEnd":2641,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java#L2605-L2641","documentation":"Error \"Association '<role>' is a '@ManyToAny' and must specify a '@JoinTable'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"An @Any/@ManyToAny mapping is missing required key-type or join information.","commonSituations":"Polymorphic @Any associations without @AnyKeyJavaType/@AnyKeyJavaClass, without any @JoinColumn, or with an unrecognized @AnyKeyType value.","solutions":["Add a @JoinTable to the @ManyToAny association 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"}