2013-07-15 65 views
0

在使用Jpa + Hibernate作爲ORM的Play Framework 1.2.5中,我想以編程方式調用Hibernate工具SchemaExport。 我試過這段代碼:在Play Framework中使用SchemaExport

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) { 
… 
} 

getPlayEjb3Configuration()是一個遊戲框架JPAPlugin.onApplicationStart()的 「複製」。

我總是獲得一個'no datasource provided'異常消息。 我嘗試保持靜態引用(修改播放框架)中的配置沒有區別。

如何從播放框架獲取正確的Ejb3Configuration/HibernateConfiguration? 還有其他方式可以調用SchemaExport嗎?

回答

0

我發現創建的SchemaExport一個解決方案:

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

和一切正常。