Hi,

wondering why OpenJPA's MappingTool refused to add a foreign key constraint
to the database (error message: openjpa.jdbc.Schema - The foreign key
"<foreignkey>" was not added to table "[...]"), I discovered that composite
foreign key support is explicitly disabled for MySQL. These are the relevant
code lines in org.apache.openjpa.jdbc.sql.MySQLDictionary:

    protected String getForeignKeyConstraintSQL(ForeignKey fk) {
        // mysql does not support composite foreign keys
        if (fk.getColumns().length > 1)
            return null;
        return super.getForeignKeyConstraintSQL(fk);
    }

For all I know, composite foreign keys are possible with MySQL. At least, a
statement like

ALTER TABLE detail ADD CONSTRAINT constraint_x FOREIGN KEY (masterId1,
masterId2) REFERENCES master (masterId1, masterId2);

works perfectly well. Are there other deficits with MySQL foreign key
handling I am not aware of or are the above lines in MySQLDictionary.java
outdated / wrong?

  Regards,
    Martin.

-- 
View this message in context: 
http://n2.nabble.com/Composite-foreign-keys-with-MySQL-tp2772257p2772257.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to