无法运行SORM示例

时间:2014-03-21 17:09:42

标签: sorm

我遇到了测试好的SORM lib的问题。

当我尝试运行这样的代码时:

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)

我得到这样的例外:

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]

我使用Play 2.10,我的数据库配置如下所示:

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

我错过了什么吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

此代码运行绝对正常。问题必须在您的设置中的某个位置。例如,为了能够使用H2数据库,您需要将其包含在项目的依赖项中。

在我成功测试代码的Maven项目中,我有以下依赖项:

<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <version>1.3.168</version>
</dependency>
相关问题