|
In Spring app, for class
import javax.persistence.*;
@Entity
@Table(name="siteroles")
public class CRole {
@Id
@GeneratedValue
private int id;
@Column(unique = true)
private String name;
@OneToMany(targetEntity = CUser.class, mappedBy = "role", cascade = CascadeType.ALL)
private List<CUser> usersOfThisRole;
/* getters, setters */
}
with
hibernate.hbm2ddl.auto=update
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect (or MySQLDialect)
Hibernate generates Sql stateements, some of which are:
DEBUG: org.hibernate.tool.hbm2ddl.SchemaUpdate - create table siteroles (id integer not null auto_increment, name varchar(255), primary key (id))
DEBUG: org.hibernate.tool.hbm2ddl.SchemaUpdate - alter table siteroles drop constraint UK_2jiev2kodqdnapqwexhhu2c8t
DEBUG: org.hibernate.tool.hbm2ddl.SchemaUpdate - alter table siteroles add constraint UK_2jiev2kodqdnapqwexhhu2c8t unique (name)
Which I use to create Sql-migration-files (with FlyWay). But turns out that
alter table siteroles drop constraint UK_2jiev2kodqdnapqwexhhu2c8t
doesn't work:
ERROR 1064 (42000): 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 UK_2jiev2kodqdnapqwexhhu2c8t' at line 1
When Hibernate runs sql statements itself, I see no errors and web application runs, db gets updated, constraint gets created (by next lines probably), but when I run them manually I get error described above, what says that SQL statement is wrong anyway.
Also "alter table drop constraint" is absent in official documentation to MySQL: http://dev.mysql.com/doc/refman/4.1/en/alter-table.html.
|