Search code examples
sorm

Could not run SORM examples


I ran into a problem testing the nice SORM lib.

When I try to run code like this:

case class Coffee(name: String, supplier: Supplier, price: Double, sales: Int, total: Int)
case class Supplier(name: String, street: String, city: String, state: String, zip: String)

object Db extends Instance(
  entities = Set(Entity[Coffee](), Entity[Supplier]()),
  url = "jdbc:h2:mem:play",
  initMode = InitMode.Create
)

val supplier1 = Supplier("Acme, Inc.", "99 Market Street", "Groundsville", "CA", "95199")
Db.save(supplier1)

I get exceptions like this:

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) ~[mchange-commons-java-0.2.3.jar:na]
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:641) ~[c3p0-0.9.2-pre5.jar:0.9.2-pre5]

I use Play 2.10 and my DB config looks like this:

 db.default.driver=org.h2.Driver
 db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=""

Am I missing something?

Thanks in advance!


Solution

  • This code runs absolutely fine. The problem must be somewhere in your setup. E.g., to be able to use H2 database you need to include it in your project's dependencies.

    In the Maven project in which I successfully tested your code I had the following dependency:

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <version>1.3.168</version>
    </dependency>