Using SchemaExport in Play Framework

2019-06-11 11:59发布

On Play Framework 1.2.5 with Jpa+Hibernate as ORM, I would like to call programmatically Hibernate tool SchemaExport. I tried this code:

Ejb3Configuration cfg = getPlayEjb3Configuration();
Configuration configuration = cfg.getHibernateConfiguration();
try {
   SchemaExport se = new SchemaExport(configuration);
   se.setHaltOnError(true);
   se.setDelimiter(";").setFormat(true);
   se.execute(true, false, false, false);
}
catch(Exception e) {
 …
}

Where getPlayEjb3Configuration() is a "copy" of play framework JPAPlugin.onApplicationStart().

I always obtain a 'no datasource provided' exception message. I try to preserve configuration in a static reference (modifying play framework) without difference.

How can I obtain from play framework a correct Ejb3Configuration/HibernateConfiguration? There's any alternative way to call SchemaExport?

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-06-11 12:27

I found a solution on creating SchemaExport:

Connection connection = ...;
SchemaExport se = SchemaExport(configuration, connection);

And everything works.

查看更多
登录 后发表回答