我昨天遇到了同样的问题。问题位于 ebean 框架的 sqlite ddl 配置内部。
但是,我能够通过创建自己的 com.avaje.ebean.config.dbplatform.SQLitePlatform 类的实现来解决这个问题。这是一个快速的技巧,它将 autoincrement 关键字设置为空字符串并将 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 文件。当放置在lib
您的播放应用程序的目录中时,类加载器将在原始实现之前加载该类,并且 sqlite 应该接受此自定义实现生成的 ddl。