Does mysql compatibility mode support foreign keys?

234 views
Skip to first unread message

Peter Voss

unread,
Apr 30, 2012, 4:04:11 AM4/30/12
to H2 Database
Hi,

the manual suggest to use MySQLDialect for Hibernate when running H2
in mysql compatibility mode. But that would be equivalent to running
mysql without foreign keys. I have also tried to use
MySQL5InnoDBDialect, but on start-up of my application I get errors
like this:

ERROR [2012-04-30 09:51:40] (SchemaUpdate.java:213) - Syntax error in
SQL statement "ALTER TABLE SHEET ADD INDEX FK6855D5FE28A19C6
(FILTER_FK),[*] ADD CONSTRAINT FK6855D5FE28A19C6 FOREIGN KEY
(FILTER_FK) REFERENCES FILTER (ID) "; SQL statement:
alter table sheet add index FK6855D5FE28A19C6 (filter_fk), add
constraint FK6855D5FE28A19C6 foreign key (filter_fk) references filter
(id) [42000-165]

The application still starts, but I don't have any foreign key checks.
I can delete entities that are referenced by other entities.

Am I doing something wrong? Or is this a bug or feature that will get
implemented sometime later?

Thanks,
Peter

Thomas Mueller

unread,
May 4, 2012, 2:44:21 AM5/4/12
to h2-da...@googlegroups.com
Hi,

H2 doesn't currently support adding multiple constraints within one statement. Each constraint must be declared within its own statement.

I guess the statement was generated by Hibernate, specially for the MySQL dialect.

To work around this problem, you can either create the constraints manually, patch H2 to support multiple constraints within one statement (patches are always welcome), or use the H2 dialect instead.

Regards,
Thomas

--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.

Reply all
Reply to author
Forward
0 new messages