In my application, I want to initialize it with large data. when I wrote all these data in one YML file it was about 4 MB but then the application didn't start making a java heap space error. when I remove some parts of it till 109 KB, everything works but of course with some missing data.
My expectation to solve this problem is one of the following:
- make more than one file, But how to refer to an object in another YML file, is this possi开发者_StackOverflowble?
- Load a schema into the database via code at start up, is this easy to make?
- a solution proposed by any of this question readers ...
Note: most of the data in my application refers to each other so I couldn't separate them in more than one file totally.
You could look at DBUnit to dump and reload your whole DB, assuming it's SQL.
I did something like that on a startup Job:
@Override
public void doJob() {
if (Image.count() == 0 && Play.mode.equals(Play.Mode.DEV)) {
Fixtures.deleteAllModels();
List<Image> images = Fixtures.loadYaml("Images.yml", List.class); //<-- this just loads the image objects (not in db yet)
Fixtures.loadModels("Albums.yml"); // <----- this puts albums into db
int i = 0;
for (Image img : images) {
img.album = Album.find("byName", img.album.name).first();
img.save(); // <--- here image entities go into db
i++;
}
}
精彩评论