我正在使用H2数据库来测试我的Grails应用。我有一些简单的域类,如:
package mypackage
class UserSession {
User user
String sessionTokenHash
// last seen info
String lastSeenIP
Date lastSeenTime
String lastSeenUserAgent
String lastSeenURL
}
但是,表似乎没有正确创建。
hbm2ddl.SchemaExport Unsuccessful: create table user_session (id bigint not null auto_increment, version bigint not null, last_seenip varchar(255) not null, last_seen_time datetime not null, last_seenurl varchar(255) not null, last_seen_user_agent varchar(255) not null, session_token_hash varchar(255) not null, user_id bigint not null, primary key (id)) ENGINE=InnoDB hbm2ddl.SchemaExport Syntax error in SQL statement "CREATE TABLE USER_SESSION (ID BIGINT NOT NULL AUTO_INCREMENT, VERSION BIGINT NOT NULL, LAST_SEENIP VARCHAR(255) NOT NULL, LAST_SEEN_TIME DATETIME NOT NULL, LAST_SEENURL VARCHAR(255) NOT NULL, LAST_SEEN_USER_AGENT VARCHAR(255) NOT NULL, SESSION_TOKEN_HASH VARCHAR(255) NOT NULL, USER_ID BIGINT NOT NULL, PRIMARY KEY (ID)) ENGINE=[*]INNODB "; expected "identifier"; SQL statement: create table user_session (id bigint not null auto_increment, version bigint not null, last_seenip varchar(255) not null, last_seen_time datetime not null, last_seenurl varchar(255) not null, last_seen_user_agent varchar(255) not null, session_token_hash varchar(255) not null, user_id bigint not null, primary key (id)) ENGINE=InnoDB [42001-147]
它设置为在create-drop
模式下使用临时内存H2数据库。
答案 0 :(得分:6)
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
我为开发数据源添加了以下行:
dialect = "org.hibernate.dialect.H2Dialect"
这解决了这个问题。