Reputation: 133
I have 2.6.5 version of Play and multimodule (several sbt submodules) configuration. I set up 2 different datasources and have Ebean error:
Caused by: javax.persistence.PersistenceException: models.common.defaultStorage.PromoBlock is NOT an Entity Bean registered with this server?
at io.ebeaninternal.server.core.DefaultServer.createQuery(DefaultServer.java:1019)
at io.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:975)
at io.ebean.Finder.query(Finder.java:157)
at models.common.defaultStorage.PromoBlock.findByProjectId(PromoBlock.java:84)
This happens only when I set up 2 datasources and appropriate mapped class settings in application.conf
.
My build.sbt
:
lazy val common = (project in file("modules/common")).enablePlugins(PlayJava, PlayEbean)
lazy val admin = (project in file("modules/admin")).enablePlugins(PlayJava, PlayEbean).dependsOn(common)
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean).aggregate(common, admin).dependsOn(common, admin)
My ebean entities live in common
module. I have only one application.conf
in the root
project and 2 datasources:
db {
default.driver = org.postgresql.Driver
default.url = "postgres://..."
mssql.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
mssql.url = "jdbc:sqlserver://..."
}
ebean.default = ["models.common.defaultStorage.*"]
ebean.mssql = ["models.common.mssqlStorage.*"]
I found out that if I comment out second ebean.mssql
option than everything is OK. But with two different lists of mapped class I got exception.
I tried use every instrution from docs https://www.playframework.com/documentation/2.6.5/JavaEbean but still no success.
My plugins.sbt
:
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.5")
...
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.0.3")
P.s. I'm migrating project from 2.4 (and previously 2.3) version of Play where everything was OK.
Upvotes: 2
Views: 523
Reputation: 827
Indeed, i have opened a PR on the play-ebean projet.
In our project we set up a workaround. But we are using Java version of Play2 and Guice. I don't know how to apply this solution in Scala. In the Module class, we have bind the DefaultEbeanConfig.EbeanConfigParser to our own class.
bind(DefaultEbeanConfig.EbeanConfigParser.class).to(CustomEbeanConfigParser.class);
Code for this class :
@Singleton
public class CustomEbeanConfigParser extends DefaultEbeanConfig.EbeanConfigParser implements Provider<EbeanConfig> {
private final Config _config;
@Inject
public CustomEbeanConfigParser(Config config, Environment environment, DBApi dbApi) {
super(config, environment, dbApi);
this._config = config;
}
@Override
public EbeanConfig parse() {
DefaultEbeanConfig ebeanConfig = (DefaultEbeanConfig) super.parse();
Map<String, ServerConfig> serverConfigMap = ebeanConfig.serverConfigs();
for (Map.Entry<String, ServerConfig> entry : serverConfigMap.entrySet()) {
entry.getValue().setDefaultServer(entry.getKey().equals(ebeanConfig.defaultServer()));
}
return ebeanConfig;
}
}
As you can see, we use the parse method of the provided parser, and after the parse, we fix the "defaultServer" attribute.
Upvotes: 3
Reputation: 21
It's a bug in latest version of play-ebean module that sets all configured datasources as default. Pull request was opened at Sep 6 but it's still not merged.
https://github.com/playframework/play-ebean/pull/125
Upvotes: 2