Hibernate version:
1.6.2
Mapping documents:
Name and version of the database you are using:
MySQL 4.0.21
Hi,
I have encountered an error using HBM2DDL (SchemaExport task in ANT).
Well, the program runs fine and produces some code to feed my MySQL Database query handler but it seems that the SQL code produced is not correct.
So, i am using MySQL 4.0.21 and hibernate 1.6.2.
I have made a little test DB schema, in mapping files and, when i use the SchemaExport task, the following code is produced:
// ----------------------------------------------------------------
alter table telephone drop constraint FK2EAEB404F06B0EBF
drop table if exists telephone
drop table if exists personne
create table telephone (
id integer not null auto_increment,
discriminator char(1) not null,
phonenumber varchar(20) not null unique,
proprietary integer not null,
relatedadress varchar(100),
operator varchar(10),
primary key (id)
)
create table personne (
id integer not null auto_increment,
birthdate varchar(8) not null,
name varchar(10) not null,
primary key (id)
)
alter table telephone add index FK2EAEB404F06B0EBF (proprietary), add constraint FK2EAEB404F06B0EBF foreign key (proprietary) references personne (id)
// ----------------------------------------------------------------
When I use my MySQL Query program (after having put a semicolon after each line), i have this error in return:
// ----------------------------------------------------------------
11:34:15.015 alter table telephone drop constraint FK2EAEB404F06B0EBF
11:34:15.015 Syntax error or access violation message from server: "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'constraint FK2EAEB404F06B0EBF' at line 1"
// ----------------------------------------------------------------
Since, until now, all the code was correct, i assume that all the parameters are set correctly (the dialect used is the MySQL dialect and so on...)
So, I looked inside the MySQL documentation, in the ALTER TABLE definition. This is what follows:
// ----------------------------------------------------------------
14.2.2 ALTER TABLE Syntax
ALTER [IGNORE] TABLE tbl_name
alter_specification [, alter_specification] ...
alter_specification:
ADD [COLUMN] column_definition [FIRST | AFTER col_name ]
| ADD [COLUMN] (column_definition,...)
| ADD INDEX [index_name] [index_type] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
PRIMARY KEY [index_type] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
UNIQUE [index_name] [index_type] (index_col_name,...)
| ADD [FULLTEXT|SPATIAL] [index_name] (index_col_name,...)
| ADD [CONSTRAINT [symbol]]
FOREIGN KEY [index_name] (index_col_name,...)
[reference_definition]
| ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
| CHANGE [COLUMN] old_col_name column_definition
[FIRST|AFTER col_name]
| MODIFY [COLUMN] column_definition [FIRST | AFTER col_name]
| DROP [COLUMN] col_name
| DROP PRIMARY KEY
| DROP INDEX index_name
| DROP FOREIGN KEY fk_symbol
| DISABLE KEYS
| ENABLE KEYS
| RENAME [TO] new_tbl_name
| ORDER BY col_name
| CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]
| [DEFAULT] CHARACTER SET charset_name [COLLATE collation_name]
| DISCARD TABLESPACE
| IMPORT TABLESPACE
| table_options
// ----------------------------------------------------------------
So, as you can see, DROP CONSTRAINT is not understood by MySQL (my version at least :-) ).
Does someone knows how to correct the problem? Perhaps the ShemaExport should be reviewed here.
Thank you in advance for all help, answer, or remarks
Jerarckill
|