title: Playframework Hibernate JPA cannot connect to Database
body: <p>I'm trying to configure Hibernate JPA to access database. Without using Hibernate JPA, It accesses to database well, but when using Hibernate JPA it does not.</p>
  
  <p>I'm following this tutorial:</p>
  
  <p><a href="https://www.playframework.com/documentation/2.5.x/JavaJPA" rel="nofollow noreferrer">https://www.playframework.com/documentation/2.5.x/JavaJPA</a></p>
  
  <p>These are my steps:</p>
  
  <h2>build.sbt</h2>
  
  <pre><code>//Hibernate JPA 
  libraryDependencies ++= Seq(   javaJpa,   "org.hibernate" % "hibernate-entitymanager" % "5.1.0.Final" // replace by your jpa implementation ) 
  
  //JPA 
  PlayKeys.externalizeResources := false
  
  //Driver for mysql 
  libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.36"
  </code></pre>
  
  <h2>conf/application.conf</h2>
  
  <pre><code>    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:3306/sakila"
          default.username = root
          default.password = "root"
  
          default.jndiName=DefaultDS
          jpa.default=defaultPersistenceUnit
  
          default.logSql=true
      }
  </code></pre>
  
  <h2>conf/META_INF/persistence.xml</h2>
  
  <pre><code>    &lt;persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
           version="2.1"&gt;
  
        &lt;persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;non-jta-data-source&gt;DefaultDS&lt;/non-jta-data-source&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/&gt;
          &lt;/properties&gt;
        &lt;/persistence-unit&gt;
      &lt;/persistence&gt;
  </code></pre>
  
  <p>Error messages:</p>
  
  <pre><code>! @70fdppp3i - Internal server error, for (GET) [/count] -&gt;
  
  play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [jpa]]
          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 play.api.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 com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
  Caused by: play.api.Configuration$$anon$1: Configuration error[either dataSource or dataSourceClassName 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: either dataSource or dataSourceClassName is required
          at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:785)
          at play.api.db.HikariCPConfig.toHikariConfig(HikariCPModule.scala:141)
          at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:57)
          at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54)
          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$lzycompute(Databases.scala:123)
          at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
          at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)
  </code></pre>
  
  <p>Error message on screen:</p>
  
  <p><a href="https://i.stack.imgur.com/ebzu5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ebzu5.png" alt="enter image description here"></a></p>
  
  <p>How to solve it?</p>
  
  <p>I'm using Play framework 2.5</p>