[play-2.5][java] ebean server instance not found for play ebean 3.0.0

710 views
Skip to first unread message

Suraj Mundada

unread,
May 23, 2016, 2:31:08 AM5/23/16
to play-framework
Hi,

I am trying to connect to mysql database using play-ebean 3.0.0. My application.conf looks as below:

play.db {
  # The combination of these two settings results in "db.default" as the
  # default JDBC pool:
  config = "db"
  default = "default"

  # Play uses HikariCP as the default connection pool.  You can override
  # settings by changing the prototype:
  prototype {
    # Sets a fixed JDBC connection pool size of 50
    hikaricp.minimumIdle = 5
    hikaricp.maximumPoolSize = 5
  }
}

db {
  # You can declare as many datasources as you want.
  # By convention, the default datasource is named `default`

  default.driver = com.mysql.jdbc.Driver
  default.url = "jdbc:mysql://localhost/temp"
  default.username = root
  default.password = "mysql"

  # You can turn on SQL logging for any datasource
  default.logSql=true
}

ebean.default = ["models.*"]


However, I am facing an issue with creating ebean server instance. 

! @7072ig267 - Internal server error, for (GET) [/] ->

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: javax.persistence.PersistenceException: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programmatically via registerServer()]]
        at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
        at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)
        at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
        at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
        at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:98)
        at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
        at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
        at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344)
        at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
Caused by: java.util.concurrent.CompletionException: javax.persistence.PersistenceException: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programmatically via registerServer()
        at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
        at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
        at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
        at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
        at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
        at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
        at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:21)
        at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:18)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
        at scala.concurrent.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:63)
Caused by: javax.persistence.PersistenceException: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programmatically via registerServer()
        at com.avaje.ebean.Ebean$ServerManager.getDefaultServer(Ebean.java:179)
        at com.avaje.ebean.Ebean$ServerManager.access$300(Ebean.java:130)
        at com.avaje.ebean.Ebean.getDefaultServer(Ebean.java:267)
        at com.avaje.ebean.Model.db(Model.java:154)
        at com.avaje.ebean.Model.save(Model.java:231)
        at controllers.HomeController.index(HomeController.java:28)
        at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:139)
        at router.Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(Routes.scala:139)
        at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:157)
        at play.core.routing.HandlerInvokerFactory$$anon$4.resultCall(HandlerInvoker.scala:156)

build.sbt is as below:

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,
  "org.avaje.ebeanorm" % "avaje-ebeanorm" % "7.11.4"
)


plugin.sbt is as below:

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0")


I tried replacing library dependency avaje-ebeanorm with enabling Play plugin PlayEbean. But it uses Ebean version 7.11.1 and it gives compiler error for importing @Cache annotation. So I am using library dependency 7.11.4

Anything missing in config?

miguel...@gmail.com

unread,
May 23, 2016, 11:01:35 AM5/23/16
to play-framework
Hi,

I also used Ebean and MySQL, for my applications.

My "application.conf" and "plugins.sbt" looks like yours

But my build.sbt is different :
lazy val root = (project in file(".")).enablePlugins(PlayJava,PlayEbean)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs
)
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.18"


i'm not able to reproduce your error message, but I think, mysql lib is missing from your file.

moreover, you use in same time org.avaje.ebeanorm" % "avaje-ebeanorm" % "7.11.4" and addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0"), i'm not sure that is it a good thing.

And when you wrote that you have "compiler error with enabiling Play plugin PlayEbean" it is compiler error from play screen or via eclipse compiler ?

Because, i have noticed, since a long time that eclipse showes some false errors compilation, just because you have to manually update the class path of you project in order to indicate to eclipse where are the JAR libraries used by play. 

On my own case, my building path is :



hope my comment help you.

Suraj Mundada

unread,
May 23, 2016, 11:42:10 AM5/23/16
to play-framework
Hi Miguel,

Thanks for your reply.

I have created a folder "lib" in my root project folder and put mysql-connector-java-5.1.38-bin.jar file there. So, mysql lib is picked up from this folder.

Compiler error is thrown from play/sbt console. It compiles fine in eclipse.

I tried to comment addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0") in plugins.sbt and run the code again. Got same "ebean server missing" error.

Also tried same config as yours:

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean)

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs
//  "org.avaje.ebeanorm" % "avaje-ebeanorm" % "7.11.4"
)

and 

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.0")

So, commented library dependency and added ebean as plugin. It gives following compilation error on sbt console

[error] F:\Installations\workspace\play\test-ebean-ignite\app\models\Employee.java:10: cannot find symbol
[error]   symbol: class Cache
[error] @Cache(enableBeanCache=true)
[error] (compile:compileIncremental) javac returned nonzero exit code

Code is as below:

package models;

import javax.persistence.Entity;
import javax.persistence.Table;

import com.avaje.ebean.Model;
import com.avaje.ebean.annotation.Cache;

@Cache(enableBeanCache=true)
@Entity
@Table(name="employee")
public class Employee extends Model {
@Id
public Integer id;



I guess there is some silly mistake in config. But not sure what it is.

Suraj Mundada

unread,
May 24, 2016, 12:21:54 AM5/24/16
to play-framework
Any idea?

Peace MICHAELS

unread,
May 25, 2016, 4:26:50 AM5/25/16
to play-framework
the version of Ebean that ships with sbt-ebean 3.0.0 is a version around 6.x (i cannot remember the exact version number), the @Cache annotation is in ebean 7.x so simply add "org.avaje.ebeanorm" % "avaje-ebeanorm" % "7.11.4" to the library dependencies of your build.sbt, do a clean and cleanAll of your project and then run. it should work without problems
Reply all
Reply to author
Forward
0 new messages