{"record":{"id":"d0f8d65498e4e010","repo":"hibernate/hibernate-orm","slug":"could-not-create-many-to-many-foreign-key-s","errorCode":null,"errorMessage":"Could not create many-to-many foreign-key : %s","messagePattern":"Could not create many-to-many foreign-key : (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ManyToManyCollectionPart.java","lineNumber":654,"sourceCode":"\t\t\t);\n\t\t}\n\n\t\tif ( fkTargetModelPart instanceof EmbeddableValuedModelPart embeddableValuedModelPart ) {\n\t\t\treturn MappingModelCreationHelper.buildEmbeddableForeignKeyDescriptor(\n\t\t\t\t\tpropertyPath,\n\t\t\t\t\tembeddableValuedModelPart,\n\t\t\t\t\tfkBootDescriptorSource,\n\t\t\t\t\tfindContainingEntityMapping(),\n\t\t\t\t\tgetCollectionDescriptor().getAttributeMapping(),\n\t\t\t\t\tnull,\n\t\t\t\t\tfalse,\n\t\t\t\t\tfkBootDescriptorSource.getColumnInsertability(),\n\t\t\t\t\tfkBootDescriptorSource.getColumnUpdateability(),\n\t\t\t\t\tcreationProcess\n\t\t\t);\n\t\t}\n\n\t\tthrow new UnsupportedOperationException(\n\t\t\t\t\"Could not create many-to-many foreign-key : \" + getNavigableRole().getFullPath()\n\t\t);\n\t}\n\n\tprivate ForeignKeyDescriptor determineForeignKey(\n\t\t\tForeignKeyDescriptor foreignKeyDescriptor,\n\t\t\tValue fkBootDescriptorSource,\n\t\t\t@Nullable String propertyPath,\n\t\t\tMappingModelCreationProcess creationProcess) {\n\t\tfinal int selectableCount = foreignKeyDescriptor.getJdbcTypeCount();\n\t\tfinal var keyPart = foreignKeyDescriptor.getKeyPart();\n\t\tfor ( int i = 0; i < selectableCount; i++ ) {\n\t\t\tfinal var selectable = keyPart.getSelectable( i );\n\t\t\tif ( selectable.isInsertable() != fkBootDescriptorSource.isColumnInsertable( i )\n\t\t\t\t|| selectable.isUpdateable() != fkBootDescriptorSource.isColumnUpdateable( i ) ) {\n\t\t\t\tfinal var attributeMapping = keyPart.asAttributeMapping();\n\t\t\t\tfinal var declaringType =\n\t\t\t\t\t\tattributeMapping == null ? null : attributeMapping.getDeclaringType();","sourceCodeStart":636,"sourceCodeEnd":672,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/ManyToManyCollectionPart.java#L636-L672","documentation":"Error \"Could not create many-to-many foreign-key : %s\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when constructing the foreign key descriptor for a many-to-many collection fails because the key mappings are inconsistent.","commonSituations":"See trigger scenarios.","solutions":["Check the many-to-many join table mapping: join columns and inverse join columns must reference existing columns of the join table.","Verify the target entity of the many-to-many is correctly mapped."],"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"}