Play Framework 2.4 Eese Id Generation

so far we have been using Play 2.3.9 and now we are moving to Play 2.4.1 When I use an old version of Play preserving Entity but with the new verifier Id is not generated. I am building a new project from scratch and tried to implement it, and the auto-generated database has an id field that is automatically incremented, and the old project has a database that uses sequences. I am trying to set up play / ebean to use sequences, but has not been successful so far.

I looked here http://www.avaje.org/topic-97.html and gave it a try, but it still doesn't work. We appreciate any suggestions.

My config looks like this:

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

      

I have also tried with

ebean.default.identityGeneration=generator

      

I put lines directly into application.conf. I also tricked with the ServerConfigStartup method of setting up ebean, but no luck.

+3


source to share


2 answers


Anyway I got it to work, in case anyone has the same problem, the following fixes:

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

      



}

+6


source


Expanding on Rob's comment in the real answer:

Input ebean.databasePlatformName=postgres8



in conf/ebean.properties

will cause the Play 2.3 option to use PostgreSQL Sequence to generate identifiers.

0


source







All Articles