【问题标题】:Ebean ORM auto create table structure in SQLiteEbean ORM在SQLite中自动创建表结构
【发布时间】:2016-02-10 21:03:02
【问题描述】:

我有一个以下模型类。只是为了测试。

@Entity
public class Quest {

    public static final Find<Long, Quest> find = new Find<Long, Quest>() {};

    @Id
    Long id;

    @Column(length=100)
    String name;

    //... Constructors/getters/setters
}

并且在尝试连接数据库的主要方法中:

public static void main(String[] args) {
    if(!AgentLoader.loadAgentFromClasspath(
        "avaje-ebeanorm-agent",
        "debug=1;packages=com.package.mmohelper.model.**")
    ) {
        throw new RuntimeException("Agent loader exception");
    }

    DataSourceConfig ds = new DataSourceConfig();
    ds.setDriver("org.sqlite.JDBC");
    ds.setUrl("jdbc:sqlite:data");
    ds.setUsername("");
    ds.setPassword("");
    ds.setIsolationLevel(Connection.TRANSACTION_SERIALIZABLE);

    ServerConfig config = new ServerConfig();
    config.setName("Sqlite");
    config.setDdlGenerate(true);
    config.setDdlRun(true);
    config.setAutoCommitMode(true);
    config.setDefaultServer(true);
    config.setDatabasePlatform(new SQLitePlatform());
    config.getDatabasePlatform().getDbDdlSyntax().setIdentity("");
    config.setDataSourceConfig(ds);

    EbeanServer server = EbeanServerFactory.create(config);

    Quest q = new Quest(0L, "Quest1");
    q.save(); // !!! Fails here !!!
}

当我运行它时,它会失败并出现以下异常:

Exception in thread "main" javax.persistence.PersistenceException: ERROR executing DML bindLog[] error[[SQLITE_ERROR] SQL error or missing database (no such table: quest)]

Caused by: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: quest)

所以,问题是:怎么了?为什么表不会自动创建?如果我想“即时”创建数据库怎么办?我应该使用普通的 JDBC 来创建表结构吗?

【问题讨论】:

    标签: java sqlite ebean


    【解决方案1】:
    @Entity
    @Table(name = "quest")
    public class Quest
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 2020-05-10
      相关资源
      最近更新 更多