openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Dirichs <>
Subject Composite foreign keys with MySQL
Date Sat, 02 May 2009 20:06:04 GMT


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
outdated / wrong?


View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message