Table creation fails

爱⌒轻易说出口 提交于 2019-12-10 17:11:47

问题


I'm using an H2 database for testing my Grails app. I have some simple domain classes like:

package mypackage

class UserSession {
    User user
    String sessionTokenHash

    // last seen info
    String lastSeenIP
    Date lastSeenTime
    String lastSeenUserAgent
    String lastSeenURL
}

however, the table doesn't seem to get created correctly.

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]

It's set to use a temporary in-memory H2 database in create-drop mode.


回答1:


I was using the wrong dialect; my DataSource.groovy had the following dialect set in the dataSource block:

dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"

I added the following line for the development data source:

dialect = "org.hibernate.dialect.H2Dialect"

This has fixed the problem.



来源:https://stackoverflow.com/questions/10195397/table-creation-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!