2016-02-05 41 views
0

如果我在ebean.properties中有这些设置,则ORM会在首次加载时设置表。Ebean ORM种子数据

ebean.ddl.generate=true 
ebean.ddl.run=true 

我在类路径中有这个create文件。

//h2-create.sql 
create table user (
    id      integer not null, 
    username     varchar(120) not null, 
    password     varchar(120) not null, 
    constraint uq_user_password unique (password), 
    constraint pk_user primary key (id)) 
; 

create sequence user_seq; 

然而,即使我添加insert语句到create文件,这并不初始数据播种到表中。

如果我还希望在加载时播种数据,我该怎么办?

回答

2

在Ebean 6.15.1你可以指定一个种子SQL脚本通过ebean.ddl.seedSql

例如运行:

ebean.ddl.generate=true 
ebean.ddl.run=true 
## only run the generated create-all dll and not the drop 
ebean.ddl.createOnly=true 

## Run test.seed.sql ... to populate some seed data prior to running the tests 
ebean.ddl.seedsql=test.seed.sql 

参考https://github.com/ebean-orm/avaje-ebeanorm/issues/515