Possible Duplicate:
Grails: error in SQL syntax when changing the hibernate dialect
我正在将 Grails 与 mySQL 数据库一起使用,并且我正在尝试更改数据库引擎。据我研究,这可以最好地完成
dialect = "org.hibernate.dialect.[MyDialect]"
在 DataSource.groovy 配置中。但是当我将方言设置为 org.hibernate.dialect.MySQLMyISAMDialect 时,我的表创建失败并出现错误:
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 'type=MyISAM' at line 1
稍后我还尝试通过以下方式更改表格:
sql.execute("ALTER TABLE book ENGINE = MYISAM;")
这确实有效,但是在创建后更改引擎时,表的所有外键都会被删除。
如何避免错误并正常更换引擎?
pav,
我正在运行 MySQL 5.5.25、Grails 2.1.0 和 grails hibernate-2.1.0 插件,它在幕后使用 hibernate-core 3.6.10.FINAL。
这可能是您的 Grails 版本(更具体地说,是 Grails 使用的 Hibernate 的底层版本)和 MySQL 版本的问题。
这是在 Hibernate JIRA: HHH-5988 上报告的错误.
我使用 InnoDB 作为我的引擎,我尝试在我的 DataSource.groovy
中交换 MyISAM:
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
// dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
dialect = "org.hibernate.dialect.MySQLMyISAMDialect"
username = "study"
password = "********"
}
我在创建表时也遇到了错误。
这是我得到的错误之一的示例,它对应于 Hibernate JIRA 上报告的错误:
| Error 2012-08-22 13:15:12,739 [pool-4-thread-1] ERROR hbm2ddl.SchemaExport
- Unsuccessful: create table user (id bigint not null auto_increment,
version bigint not null,
login varchar(255) not null unique,
password varchar(255) not null,
role varchar(5) not null,
primary key (id)) type=MyISAM
对上述 Hibernate JIRA 错误的评论之一是一位用户正在创建自己的 custom dialect for MySQL 5 MyISAM .