【问题标题】:Play Framework 2.4 Ebean Id GenerationPlay Framework 2.4 Ebean Id生成
【发布时间】:2015-06-26 10:48:28
【问题描述】:

到目前为止,我们一直在使用 Play 2.3.9,现在我们正在迁移到 Play 2.4.1。当我使用旧版本的 Play 保存实体时,可以使用新版本,但不会生成 ID。我从头开始设置一个新项目并尝试它来实现它的工作,并且自动生成的数据库有一个自动递增的 Id 字段,而旧项目有一个使用序列的数据库。我一直在尝试将 play/ebean 配置为使用序列,但到目前为止还没有成功。

我在这里查看了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 中,我也用 ServerConfigStartup 配置 ebean 的方式愚弄了,但没有运气。

【问题讨论】:

    标签: playframework playframework-2.0 ebean


    【解决方案1】:

    不管怎样,我得到了它的工作,如果有人有同样的问题,以下修复它:

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

    }

    【讨论】:

    • github.com/ebean-orm/avaje-ebeanorm/issues/97 的引用在 Postgres SERIAL 上的 Ebean 版本 4.0.5 成为默认 ID 机制。您上面的解决方案很好 - 或者您可以使用较旧的“平台”:ebean.databasePlatformName=postgres8
    【解决方案2】:

    将 Rob 的评论扩展为真正的答案:

    推杆 ebean.databasePlatformName=postgres8

    conf/ebean.properties 将强制 Play 2.3 默认使用 PostgreSQL 序列生成 ID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多