问题
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