在Play框架中使用SchemaExport [英] Using SchemaExport in Play Framework

查看:163
本文介绍了在Play框架中使用SchemaExport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jpa + Hibernate作为ORM的Play Framework 1.2.5上,我想以编程方式调用Hibernate工具SchemaExport。
我试过这段代码:

  Ejb3Configuration cfg = getPlayEjb3Configuration(); 
配置配置= cfg.getHibernateConfiguration();
尝试{
SchemaExport se = new SchemaExport(configuration);
se.setHaltOnError(true);
se.setDelimiter(;)。setFormat(true);
se.execute(true,false,false,false);

catch(例外e){
...
}

其中 getPlayEjb3Configuration()是播放框架 JPAPlugin.onApplicationStart()的副本 p>

我总是获得一个'no datasource provided'异常消息。
我试图在静态引用中保留配置(修改播放框架),没有任何区别。



如何从播放框架获得正确的Ejb3Configuration / HibernateConfiguration?
有任何其他方式可以调用SchemaExport?

解决方案

我找到了创建SchemaExport的解决方案:

 连接连接= ...; 
SchemaExport se = SchemaExport(configuration,connection);

一切正常。


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?

解决方案

I found a solution on creating SchemaExport:

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

And everything works.

这篇关于在Play框架中使用SchemaExport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆