1
votes

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.

  1. Defining a database and the Ebean configuration in the [root]/conf/application.conf and the other one in [root]/modules/sub/conf/application.conf (with different database names). Then I get an error "CreationException: Unable to create injector, see the following errors: 1) Error injecting constructor, java.lang.IllegalStateException: Bean class models.RootModel is not enhanced?"
  2. Defining one database and the Ebean configuration in root's configuration and one in the subproject's configuration with the same database name. Then I get an error "PersistenceException: subproject.models.SubModel is NOT an Entity Bean registered with this server?"
  3. Defining both databases and Ebean configuration in the root project and define the database for the subproject in its configuration, same error like in 1.
  4. No configuration in my subproject, error: "CreationException: Unable to create injector, see the following errors: 1) Error injecting constructor, java.lang.IllegalStateException: Bean class subproject.models.SubModel is not enhanced?"

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.*"]
1

1 Answers

0
votes

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.