Search code examples
h2ebeanplayframework-2.5

Ebean and H2 configuration issue with Play framework 2.5


I am trying to develop with Play Framework version 2.5, and I cannot get the database connection right. I am using H2 database with Ebean plugin 3.0.2 as an ORM. I tried several options for the entries in application.conf, based on the information found on Play Framework website and many of your posts. Please find below the entries to my configuration files and the error trace and help me :

      **Application.conf**

      play.db {
      # The combination of these two settings results in "db.default" as the
      #default JDBC pool:
      config = "db"
      default = "default"
      prototype {
           # Sets a fixed JDBC connection pool size of 50
           #hikaricp.minimumIdle = 50
           #hikaricp.maximumPoolSize = 50

                }
      }

   db { 
     default.hikaricp.dataSourceClassName = org.h2.jdbcx.JdbcDataSource
     default.driver = org.h2.Driver
     default.url = "jdbc:h2:mem:play"
     default.username = sa
     default.password = ""
     ebean.default = ["models.*"] 
     #play.ebean.default.dataSource = default

      default.logSql=true
     }
     **Plugins.sbt**

    addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.10")

   // Web plugins
   addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
   addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")
   addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.4")
   addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.8")
   addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.1")
   addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")


    addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.6")
   addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
   enablePlugins(PlayEbean).
   addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "3.0.2")
   addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % 

  "5.0.1")

  **Build.sbt**




   name := """Institut"""

     version := "1.0-SNAPSHOT"

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

     scalaVersion := "2.11.7"

      libraryDependencies ++= Seq(
      javaJdbc,
      cache,
      javaWs,
      evolutions

     )



  **Console output**



   [info] application - Creating Pool for datasource 'ebean'
   [error] c.z.h.HikariConfig - HikariPool-1 - dataSource or
   dataSourceClassName
   or jdbcUrl is required.
   [info] application - Creating Pool for datasource 'ebean'
   [error] c.z.h.HikariConfig - HikariPool-2 - dataSource or 
   dataSourceClassName
   or jdbcUrl is required.
   [info] application - Creating Pool for datasource 'ebean'
   [error] c.z.h.HikariConfig - HikariPool-3 - dataSource or 
   dataSourceClassName
   or jdbcUrl is required.
   [info] application - Creating Pool for datasource 'ebean'
   [error] c.z.h.HikariConfig - HikariPool-4 - dataSource or 
   dataSourceClassName
   or jdbcUrl is required.
   [error] application - 

   ! @736eodoo7 - Internal server error, for (GET) [/] ->

    play.api.Configuration$$anon$1: Configuration error[Cannot connect to
    database [ebean]]
    at play.api.Configuration$.configError(Configuration.scala:154)
    at play.api.Configuration.reportError(Configuration.scala:806)
    at 
    play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48)
    at playi.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42)
    at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72)
    at play.api.db.DBApiProvider.get(DBModule.scala:62)
    at play.api.db.DBApiProvider.get(DBModule.scala:58)
    at            
    Caused by: play.api.Configuration$$anon$1: Configuration
    error[dataSource or
    dataSourceClassName or jdbcUrl is required.]
    at play.api.Configuration$.configError(Configuration.scala:154)
    at play.api.PlayConfig.reportError(Configuration.scala:996)
    at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:70)
    at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
    at 
    play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:123)
    at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:138)
    at 
    play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:44)
    at
    play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42)
    Caused by: java.lang.IllegalArgumentException: dataSource or 
    dataSourceClassName or jdbcUrl is required.
    at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:786)
    at play.api.db.HikariCPConfig.toHikariConfig(HikariCPModule.scala:141)
    at              

    at scala.util.Try$.apply(Try.scala:192)
    at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54)
    at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
    at 
    play.api.db.DefaultDatabase.dataSource$lazycompute(Databases.scala:123)
    at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)

I had the same error message with H2 configuration , which was resolved be adding the dataSourceClassName, however I have tried to use default as datasource for Ebean without success. Thank you !


Solution

  • ebean.default = ["models.*"] is not a member of the key db.default you have to place it outside of db.

    According to your log ebean thinks that this key is another database

    play.api.Configuration$$anon$1: Configuration error[Cannot connect to
        database [ebean]]
    

    More info here:

    https://www.playframework.com/documentation/2.5.x/JavaDatabase#H2-database-engine-connection-properties