Heys guys,
I hope you can really help me with subprojects in Play Framework 2.4.x. I'm developing a Play project (I call it root) with a subproject. Both do have ebean models and I want to save these models in different databases. I tried many possibilies but I'm not able to work it out.
How do I setup the databases for my Play Framework project and its subproject?
My files are in these folders:
[root]/build.sbt
[root]/conf/application.conf
[root]/app/models/RootModel.java
[root]/modules/sub/conf/application.conf
[root]/modules/sub/conf/app/models/subproject/models/SubModel.java
My [root]/build.sbt:
import com.typesafe.play.sbt.enhancer.PlayEnhancer
name := """rootproject"""
version := "1.0"
lazy val root = (project in file("."))
.enablePlugins(PlayJava, PlayEbean, PlayEnhancer)
.aggregate(sub)
.dependsOn(sub)
.settings(
TwirlKeys.templateImports += "subproject.models._"
)
lazy val sub = project.in(file("modules/sub"))
.enablePlugins(PlayJava, PlayEbean, PlayEnhancer)
scalaVersion := "2.11.6"
Defining of the database and ebean configuration in the application.conf:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:./db/default;DB_CLOSE_DELAY=-1"
db.default.username="sa"
db.default.password="..."
db.sub.driver=org.h2.Driver
db.sub.url="jdbc:h2:./db/sub;DB_CLOSE_DELAY=-1"
db.sub.username="sa"
db.sub.password="..."
ebean.default=["models.*"]
ebean.sub=["subproject.models.*"]
Okay, I figured it out myself. It's quite simple, look at the Play Framework Documentation.
If you're having problems like 'PersistenceException: sub.model.SubModel is NOT an Entity Bean registered with this server?', then look at Multiple Databases with Play Framework 2.1.x.