2015-06-26 61 views
2

直到現在我們一直在使用Play 2.3.9,現在我們正在遷移到Play 2.4.1當我使用舊版本的Play時,保存一個Entity的作品,但新版本的Id不是產生。我從頭開始設置一個新項目,並嘗試實現它,並且自動生成的數據庫具有自動遞增的Id字段,而舊項目具有使用序列的數據庫。我一直在嘗試配置play/ebean來使用序列,但到目前爲止還沒有成功。Play Framework 2.4 Ebean Id的生成

我在這裏看了一下http://www.avaje.org/topic-97.html並給了它一個嘗試,但它仍然沒有工作。任何建議,將不勝感激。

我的配置是這樣的:

ebean.default.identityGeneration=sequence 
ebean.default.supportsGetGeneratedKeys=false 
ebean.default.supportsSequences=true 
ebean.default.debug.sql=true 

我也試圖與

ebean.default.identityGeneration=generator 

我把直接application.conf我也配置ebean但對ServerConfigStartup方式愚弄與周圍的線條沒有運氣。

回答

5

不管怎麼說,我得到它的工作,如果任何人有同樣的問題,以下修復它:

public class MyServerConfigStartup implements ServerConfigStartup { 
@Override 
public void onStart(ServerConfig serverConfig) { 
    PostgresPlatform postgresPlatform = new PostgresPlatform(); 
    DbIdentity dbIdentity = postgresPlatform.getDbIdentity(); 
    dbIdentity.setSupportsGetGeneratedKeys(false); 
    dbIdentity.setSupportsSequence(true); 
    dbIdentity.setIdType(IdType.GENERATOR); 
    serverConfig.setDatabasePlatform(postgresPlatform); 
} 

}的

+1

參考https://github.com/ebean-orm/avaje- ebeanorm/issues/97隨着PostgreSQL上的Ebean版本4.0.5 SERIAL成爲默認的ID機制。上面的解決方案很好 - 或者您可以使用舊的「平臺」:ebean.databasePlatformName = postgres8 –

相關問題