我正在使用play框架2.1,并使用进化为我自动生成sql脚本。我使用的数据库是sqlite3。
似乎进化不能为sqlite3生成正确的脚本。我得到的错误脚本是:
create table algorithm (
id bigint AUTOINCREMENT primary key,
name varchar(255),
description varchar(255))
;我是sqlite3的新手。通过在线搜索,我意识到:
autoincrement只能与Integer一起工作autoincrement应该放在primary key之后所以很明显,自动生成的脚本是不正确的。我的问题是:
发布于 2013-04-30 13:26:58
我昨天也遇到了同样的问题。问题位于ebean框架的sqlite配置中。
但是,通过创建自己的com.avaje.ebean.config.dbplatform.SQLitePlatform类实现,我能够解决这个问题。这是一种快速攻击,它将自动递增关键字设置为空字符串,并将bigint类型重新定义为整型:
package com.avaje.ebean.config.dbplatform;
import java.sql.Types;
import javax.sql.DataSource;
import com.avaje.ebean.BackgroundExecutor;
public class SQLitePlatform extends DatabasePlatform {
static {
System.err.println("\n\n!!! Custom SQLitePlatform class for ebean ORM loaded !!!!\n\n");
}
public SQLitePlatform() {
super();
this.name = "sqlite";
this.dbIdentity.setIdType(IdType.IDENTITY);
this.dbIdentity.setSupportsGetGeneratedKeys(false);
this.dbIdentity
.setSelectLastInsertedIdTemplate("select last_insert_rowid()");
this.openQuote = "\"";
this.closeQuote = "\"";
this.booleanDbType = Types.INTEGER;
dbTypeMap.put(Types.BIT, new DbType("int default 0"));
dbTypeMap.put(Types.BOOLEAN, new DbType("int default 0"));
dbTypeMap.put(Types.BIGINT, new DbType("integer"));
dbDdlSyntax.setInlinePrimaryKeyConstraint(true);
dbDdlSyntax.setIdentity("");
dbDdlSyntax.setDisableReferentialIntegrity("PRAGMA foreign_keys = OFF");
dbDdlSyntax.setEnableReferentialIntegrity("PRAGMA foreign_keys = ON");
}
/**
* Return null in case there is a sequence annotation.
*/
@Override
public IdGenerator createSequenceIdGenerator(BackgroundExecutor be,
DataSource ds, String seqName, int batchSize) {
return null;
}
}编译类并将其打包到jar文件中。当放置在play应用程序的lib目录中时,类加载器将在原始实现之前加载类,sqlite应该接受这个自定义实现生成的ddl。
https://stackoverflow.com/questions/15733941
复制相似问题