java - Multiple Databases with Play Framework 2.1.x -
i have 2 databases need connect to. can connect them in application.conf file so:
db.default.driver=org.postgresql.driver db.default.url="jdbc:postgresql://localhost/db1" db.default.user=postgres db.default.password="password" db.secondary.driver=org.postgresql.driver db.secondary.url="jdbc:postgresql://localhost/db2" db.secondary.user=postgres db.secondary.password="password" ebean.default="models.db1.*" ebean.secondary="models.db2.*"
i have model classes in packages, , ddl generates tables properly.
the problem lies in working these entities. not in "default" package throws error (using users table in secondary database example)
if try query rows of table:
list<users> users = users.find.all();
it throws error:
[persistenceexception: models.db2.users not entity bean registered server?]
even though 100% sure users table there in backend, registered table ddl works , makes table properly, , importing proper classes.
is there way need query model classes aren't in default package?
edit: realize stack trace shows it's trying use defaultserver. how can make use secondary server?
@ com.avaje.ebeaninternal.server.core.defaultserver.createquery(defaultserver.java:989) ~[avaje-ebeanorm-server.jar:na] @ com.avaje.ebeaninternal.server.core.defaultserver.createquery(defaultserver.java:946) ~[avaje-ebeanorm-server.jar:na] @ com.avaje.ebeaninternal.server.core.defaultserver.find(defaultserver.java:982) ~[avaje-ebeanorm-server.jar:na] @ play.db.ebean.model$finder.all(model.java:254) ~[play-java-ebean_2.10.jar:2.1.3]
ok, application.conf
seems correct.
you may use secondary server this:
ebeanserver secondary = ebean.getserver("secondary"); secondary.find(user.class).findlist();
once you've got secondary server, may treat treat ebean
singleton.