SchemaExport is not adding 'CASCADE ON ..." when it creates foreign keys during the schema creation. I have a feeling that this is specific to using org.hibernate.dialect.MySQL5InnoDBDialect and the translation between the JPA annotations and the SQL.
With hibernate.hbm2ddl.auto set to 'create' I get the SQL shown in the log below. From what I understand, both foreign key constraints should have 'on delete cascade' at the end of them.
Hibernate Core version: 3.2.2
Hibernate Annotations version: 3.2.1
Hibernate Entity Manager version: 3.2.1
Name and version of the database you are using: MySQL 5.0 InnoDB
The generated SQL (show_sql=true):
15:54:05,387 DEBUG SchemaExport:303 - create table FirstTable (id integer not null auto_increment, primary key (id)) ENGINE=InnoDB
15:54:05,507 DEBUG SchemaExport:303 - create table FirstTable_SecondTable (FirstTable_id integer not null, seconds_id integer not null) ENGINE=InnoDB
15:54:05,627 DEBUG SchemaExport:303 - create table SecondTable (id integer not null auto_increment, primary key (id)) ENGINE=InnoDB
15:54:05,747 DEBUG SchemaExport:303 - alter table FirstTable_SecondTable add index FK95CB7BF97BA45F79 (FirstTable_id), add constraint FK95CB7BF97BA45F79 foreign key (FirstTable_id) references FirstTable (id)
15:54:06,038 DEBUG SchemaExport:303 - alter table FirstTable_SecondTable add index FK95CB7BF91A00BD6 (seconds_id), add constraint FK95CB7BF91A00BD6 foreign key (seconds_id) references SecondTable (id)
15:54:06,298 INFO SchemaExport:196 - schema export complete
The java files:
Code:
@Entity
public class FirstTable
{
@Id
@GeneratedValue
private int id;
@ManyToMany(cascade=CascadeType.REMOVE)
List<SecondTable> seconds;
}
Code:
@Entity
public class SecondTable
{
@Id
@GeneratedValue
private int id;
}
This does appear to be a bug to me, but I'd like to get some feedback before I file it on JIRA. Any comments/questions are appreciated!
Thanks,
Jim