Play Framework 2.4 Ebean Id Generation

99封情书 提交于 2020-01-02 06:57:22

问题


until now we have been using Play 2.3.9 and we are now migrating to Play 2.4.1 When I use the old version of Play saving an Entity works but with the new verion the Id is not generated. I setup a new project from scratch and tried it to realize it works and the auto generated database has an Id field that auto increments while the old project has a database that uses sequences. I have been trying to configure play/ebean to use sequences but have not been succesfull thus far.

I took a look here http://www.avaje.org/topic-97.html and gave it a try but its still not working. Any suggestions would be appreciated.

My config looks like this:

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

I also tried with

ebean.default.identityGeneration=generator

I put the lines directly in application.conf I also fooled around with the ServerConfigStartup way of configuring ebean but no luck.


回答1:


Anyways, I got it to work, if anyone has the same problem the following fixes it:

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);
}

}




回答2:


Expanding Rob's comment into a real answer:

Putting ebean.databasePlatformName=postgres8

in conf/ebean.properties will force the Play 2.3 default of using a PostgreSQL Sequence to generate IDs.



来源:https://stackoverflow.com/questions/31071253/play-framework-2-4-ebean-id-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!