Play Framework 2.4 Ebean Id生成 [英] Play Framework 2.4 Ebean Id Generation
问题描述
直到现在我们一直在使用Play 2.3.9,并且现在正在迁移到Play 2.4.1.当我使用旧版本的Play时,保存实体有效,但使用新版本时,不会生成ID.我从头开始设置了一个新项目,并尝试使其实现,并且自动生成的数据库具有一个ID字段,该字段自动递增,而旧项目具有一个使用序列的数据库.我一直在尝试将play/ebean配置为使用序列,但到目前为止尚未成功.
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.
我在这里查看了 http://www.avaje.org/topic-97.html 并尝试了一下,但仍然无法正常工作.任何建议,将不胜感激.
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.
我的配置如下:
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方法.
I put the lines directly in application.conf I also fooled around with the ServerConfigStartup way of configuring ebean but no luck.
推荐答案
无论如何,我都能正常工作,如果有人遇到相同的问题,则可以通过以下方法对其进行修复:
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);
}
}
这篇关于Play Framework 2.4 Ebean Id生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!