I have a test app that works fine with an H2 in-memory database. Now I'm trying to connect it to our real database. I'm either getting an internal Slick exception, or a "No suitable driver" exception, depending on my approach:
Here's my simple test (which, again, seems to work fine in-memory):
"The glimple data model classes" should {
"insert a glimple row in the database" in {
val db = Database.forConfig("db.edb") // works on db.h2mem1
val glimples = TableQuery[GPGlimpleModel]
val insertGlimples = db.run(glimples += GPGlimple(None, None, 1, true, true, 1))
val count = Await.result(insertGlimples, Duration.Inf)
println(count)
count must beEqualTo(1)
...
If I turn on the connection pool, as noted here:
db.edb = {
driver = org.postgresql.Driver
url = "jdbc:postgresql://db-server-1.hyrax.com:5444/CI_0"
user = "xxx" // masked to protect the innocent
password = "xxx" // masked to protect the innocent
keepAliveConnection = true
// connectionPool = disabled
}
I end up getting the following exception. In trying to decipher what's going on, I started with a connection pool enabled (as in, "connectionPool = enabled" or just commenting that line out). That led to more problems and a very, very long exception (shown at the end of this post).
The head of that exception is:
[error] [error] java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariConfig [error] caused by java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariConfig
And that just makes no sense to me... because again, it works just fine in-memory.
And here's the build.sbt driver line for Postgres:
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41",
Following is the full exception... I've posted it to github as suggested at the end of the trace:
[error] [error] java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariConfig [error] caused by java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariConfig [error] [error] STACKTRACE [error]
slick.jdbc.HikariCPJdbcDataSource$.forConfig(JdbcDataSource.scala:141) [error]
slick.jdbc.HikariCPJdbcDataSource$.forConfig(JdbcDataSource.scala:135) [error]
slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:35) [error] slick.jdbc.JdbcBackend$DatabaseFactoryDef$class.forConfig(JdbcBackend.scala:223) [error]
slick.jdbc.JdbcBackend$$anon$3.forConfig(JdbcBackend.scala:33) [error] models.TestGlimpleModel$$anonfun$1$$anonfun$apply$64$$anonfun$apply$65.apply(TestGlimpleModel.scala:166) [error]
models.TestGlimpleModel$$anonfun$1$$anonfun$apply$64$$anonfun$apply$65.apply(TestGlimpleModel.scala:158) [error]
org.specs2.matcher.MatchResult$$anon$12$$anonfun$asResult$1.apply(MatchResult.scala:310) [error]
org.specs2.matcher.MatchResult$$anon$12$$anonfun$asResult$1.apply(MatchResult.scala:310) [error]
org.specs2.execute.ResultExecution$class.execute(ResultExecution.scala:25) [error]
org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:120) [error]
org.specs2.execute.Result$$anon$10.asResult(Result.scala:230) [error] org.specs2.execute.AsResult$.apply(AsResult.scala:25) [error]
org.specs2.matcher.MatchResult$$anon$12.asResult(MatchResult.scala:310) [error] org.specs2.execute.AsResult$.apply(AsResult.scala:25) [error]
org.specs2.main.CommandLineAsResult$$anon$1.asResult(CommandLineAsResult.scala:17) [error]
org.specs2.main.CommandLineAsResult$$anonfun$apply$1.apply(CommandLineAsResult.scala:21) [error]
org.specs2.main.CommandLineAsResult$$anonfun$apply$1.apply(CommandLineAsResult.scala:21) [error]
org.specs2.specification.dsl.mutable.ExampleDsl1$BlockExample$$anonfun$$greater$greater$1.apply(ExampleDsl.scala:39) [error]
org.specs2.specification.dsl.mutable.ExampleDsl1$BlockExample$$anonfun$$greater$greater$1.apply(ExampleDsl.scala:39) [error]
org.specs2.specification.core.Execution$$anonfun$withEnv$1$$anonfun$apply$3.apply(Execution.scala:120) [error]
org.specs2.execute.ResultExecution$class.execute(ResultExecution.scala:25) [error]
org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:120) [error]
org.specs2.execute.Result$$anon$10.asResult(Result.scala:230) [error] org.specs2.execute.AsResult$.apply(AsResult.scala:25) [error]
org.specs2.specification.core.Execution$$anonfun$withEnv$1.apply(Execution.scala:120) [error]
org.specs2.specification.core.Execution$$anonfun$withEnv$1.apply(Execution.scala:120) [error]
org.specs2.specification.core.Execution$$anonfun$execute$2$$anonfun$apply$2.apply(Execution.scala:70) [error]
org.specs2.specification.core.Execution$$anonfun$execute$2$$anonfun$apply$2.apply(Execution.scala:70) [error]
org.specs2.specification.core.Execution.setResult(Execution.scala:76) [error]
org.specs2.specification.core.Execution$$anonfun$execute$2.apply(Execution.scala:70) [error]
org.specs2.specification.core.Execution$$anonfun$execute$2.apply(Execution.scala:70) [error] scala.Option.fold(Option.scala:158) [error]
org.specs2.specification.core.Execution.execute(Execution.scala:70) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$executeFragment$1$$anonfun$apply$6.apply(Executor.scala:132) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$executeFragment$1$$anonfun$apply$6.apply(Executor.scala:130) [error]
org.specs2.specification.core.Fragment.updateExecution(Fragment.scala:44) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$executeFragment$1.apply(Executor.scala:130) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$executeFragment$1.apply(Executor.scala:129) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$sequencedExecution$1.executedFragment$lzycompute$1(Executor.scala:104) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$sequencedExecution$1.org$specs2$specification$process$DefaultExecutor$class$$anonfun$$executedFragment$1(Executor.scala:104) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$sequencedExecution$1$$anonfun$3.apply(Executor.scala:109) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$sequencedExecution$1$$anonfun$3.apply(Executor.scala:109) [error]
scalaz.concurrent.Task$$anonfun$delay$1.apply(Task.scala:272) [error] scalaz.concurrent.Task$$anonfun$delay$1.apply(Task.scala:272) [error] scalaz.concurrent.Task$$anonfun$suspend$1$$anonfun$4.apply(Task.scala:280) [error]
scalaz.concurrent.Task$$anonfun$suspend$1$$anonfun$4.apply(Task.scala:280) [error] scalaz.concurrent.Task$.Try(Task.scala:385) [error]
scalaz.concurrent.Task$$anonfun$suspend$1.apply(Task.scala:280) [error]
scalaz.concurrent.Task$$anonfun$suspend$1.apply(Task.scala:280) [error] scalaz.concurrent.Future.step(Future.scala:111) [error]
scalaz.concurrent.Future.listen(Future.scala:76) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:310) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:309) [error] scala.collection.Iterator$class.foreach(Iterator.scala:750) [error]
scala.collection.AbstractIterator.foreach(Iterator.scala:1202) [error] scala.collection.IterableLike$class.foreach(IterableLike.scala:72) [error] scala.collection.AbstractIterable.foreach(Iterable.scala:54) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:309) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:305) [error] scalaz.concurrent.Future.listen(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error] scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free.resume(Free.scala:73) [error]
scalaz.Free.go2$1(Free.scala:118) [error]
scalaz.Free.go(Free.scala:122) [error]
scalaz.Free.run(Free.scala:172) [error]
scalaz.concurrent.Future.listen(Future.scala:77) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:310) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:309) [error] scala.collection.Iterator$class.foreach(Iterator.scala:750) [error]
scala.collection.AbstractIterator.foreach(Iterator.scala:1202) [error] scala.collection.IterableLike$class.foreach(IterableLike.scala:72) [error] scala.collection.AbstractIterable.foreach(Iterable.scala:54) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:309) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:305) [error] scalaz.concurrent.Future.listen(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error] scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free.resume(Free.scala:73) [error]
scalaz.Free.go2$1(Free.scala:118) [error]
scalaz.Free.go(Free.scala:122) [error]
scalaz.Free.run(Free.scala:172) [error]
scalaz.concurrent.Future.listen(Future.scala:77) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:310) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:309) [error] scala.collection.Iterator$class.foreach(Iterator.scala:750) [error]
scala.collection.AbstractIterator.foreach(Iterator.scala:1202) [error] scala.collection.IterableLike$class.foreach(IterableLike.scala:72) [error] scala.collection.AbstractIterable.foreach(Iterable.scala:54) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:309) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:305) [error] scalaz.concurrent.Future.listen(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error] scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free.resume(Free.scala:73) [error]
scalaz.Free.go2$1(Free.scala:118) [error]
scalaz.Free.go(Free.scala:122) [error]
scalaz.Free.run(Free.scala:172) [error]
scalaz.concurrent.Future.listen(Future.scala:77) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:310) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:309) [error] scala.collection.Iterator$class.foreach(Iterator.scala:750) [error]
scala.collection.AbstractIterator.foreach(Iterator.scala:1202) [error] scala.collection.IterableLike$class.foreach(IterableLike.scala:72) [error] scala.collection.AbstractIterable.foreach(Iterable.scala:54) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:309) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:305) [error] scalaz.concurrent.Future.listen(Future.scala:80) [error]
scalaz.concurrent.Future.runAsync(Future.scala:143) [error]
scalaz.concurrent.Future.run(Future.scala:160) [error]
scalaz.concurrent.Task.attemptRun(Task.scala:104) [error]
org.specs2.control.ActionT$.fromTask(ActionT.scala:125) [error]
org.specs2.control.ActionTSupport$class.fromTask(ActionT.scala:188) [error]
org.specs2.control.package$Actions$.fromTask(package.scala:29) [error] org.specs2.reporter.Reporter$$anonfun$report$1.apply(Reporter.scala:47) [error]
org.specs2.reporter.Reporter$$anonfun$report$1.apply(Reporter.scala:37) [error]
org.specs2.runner.SbtRunner$$anonfun$specificationRun$1$$anonfun$2.apply(SbtRunner.scala:75) [error]
org.specs2.runner.SbtRunner$$anonfun$specificationRun$1$$anonfun$2.apply(SbtRunner.scala:75) [error]
org.specs2.control.ActionT$$anonfun$flatMap$1$$anonfun$apply$2.apply(ActionT.scala:36) [error]
org.specs2.control.ActionT$$anonfun$flatMap$1$$anonfun$apply$2.apply(ActionT.scala:36) [error]
org.specs2.control.StatusT$$anonfun$flatMap$1.apply(StatusT.scala:20) [error]
org.specs2.control.StatusT$$anonfun$flatMap$1.apply(StatusT.scala:19) [error] scala.Function1$$anonfun$andThen$1.apply(Function1.scala:55) [error] scalaz.WriterT$$anonfun$flatMapF$1.apply(WriterT.scala:63) [error] scalaz.WriterT$$anonfun$flatMapF$1.apply(WriterT.scala:62) [error]
scalaz.effect.IO$$anonfun$flatMap$1$$anonfun$apply$9.apply(IO.scala:62) [error]
scalaz.effect.IO$$anonfun$flatMap$1$$anonfun$apply$9.apply(IO.scala:61) [error]
scalaz.Free$$anonfun$flatMap$1$$anonfun$apply$1.apply(Free.scala:60) [error]
scalaz.Free$$anonfun$flatMap$1$$anonfun$apply$1.apply(Free.scala:60) [error] scalaz.Free.resume(Free.scala:72) [error]
scalaz.Free.go2$1(Free.scala:118) [error]
scalaz.Free.go(Free.scala:122) [error]
scalaz.Free.run(Free.scala:172) [error]
scalaz.effect.IO$class.unsafePerformIO(IO.scala:22) [error]
scalaz.effect.IOFunctions$$anon$6.unsafePerformIO(IO.scala:227) [error]
org.specs2.runner.SbtRunner$$anonfun$newTask$1$$anon$4.execute(SbtRunner.scala:40) [error] sbt.ForkMain$Run$2.call(ForkMain.java:294) [error]
sbt.ForkMain$Run$2.call(ForkMain.java:284) [error]
java.util.concurrent.FutureTask.run(FutureTask.java:266) [error]
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [error]
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [error] java.lang.Thread.run(Thread.java:745) [error] [error]
CAUSED BY java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariConfig [error]
java.net.URLClassLoader$1.run(URLClassLoader.java:372) [error]
java.net.URLClassLoader$1.run(URLClassLoader.java:361) [error]
java.security.AccessController.doPrivileged(Native Method) [error]
java.net.URLClassLoader.findClass(URLClassLoader.java:360) [error]
java.lang.ClassLoader.loadClass(ClassLoader.java:424) [error]
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) [error] java.lang.ClassLoader.loadClass(ClassLoader.java:357) [error]
slick.jdbc.HikariCPJdbcDataSource$.forConfig(JdbcDataSource.scala:141) [error]
slick.jdbc.HikariCPJdbcDataSource$.forConfig(JdbcDataSource.scala:135) [error]
slick.jdbc.JdbcDataSource$.forConfig(JdbcDataSource.scala:35) [error] slick.jdbc.JdbcBackend$DatabaseFactoryDef$class.forConfig(JdbcBackend.scala:223) [error]
slick.jdbc.JdbcBackend$$anon$3.forConfig(JdbcBackend.scala:33) [error] models.TestGlimpleModel$$anonfun$1$$anonfun$apply$64$$anonfun$apply$65.apply(TestGlimpleModel.scala:166) [error]
models.TestGlimpleModel$$anonfun$1$$anonfun$apply$64$$anonfun$apply$65.apply(TestGlimpleModel.scala:158) [error]
org.specs2.matcher.MatchResult$$anon$12$$anonfun$asResult$1.apply(MatchResult.scala:310) [error]
org.specs2.matcher.MatchResult$$anon$12$$anonfun$asResult$1.apply(MatchResult.scala:310) [error]
org.specs2.execute.ResultExecution$class.execute(ResultExecution.scala:25) [error]
org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:120) [error]
org.specs2.execute.Result$$anon$10.asResult(Result.scala:230) [error] org.specs2.execute.AsResult$.apply(AsResult.scala:25) [error]
org.specs2.matcher.MatchResult$$anon$12.asResult(MatchResult.scala:310) [error] org.specs2.execute.AsResult$.apply(AsResult.scala:25) [error]
org.specs2.main.CommandLineAsResult$$anon$1.asResult(CommandLineAsResult.scala:17) [error]
org.specs2.main.CommandLineAsResult$$anonfun$apply$1.apply(CommandLineAsResult.scala:21) [error]
org.specs2.main.CommandLineAsResult$$anonfun$apply$1.apply(CommandLineAsResult.scala:21) [error]
org.specs2.specification.dsl.mutable.ExampleDsl1$BlockExample$$anonfun$$greater$greater$1.apply(ExampleDsl.scala:39) [error]
org.specs2.specification.dsl.mutable.ExampleDsl1$BlockExample$$anonfun$$greater$greater$1.apply(ExampleDsl.scala:39) [error]
org.specs2.specification.core.Execution$$anonfun$withEnv$1$$anonfun$apply$3.apply(Execution.scala:120) [error]
org.specs2.execute.ResultExecution$class.execute(ResultExecution.scala:25) [error]
org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:120) [error]
org.specs2.execute.Result$$anon$10.asResult(Result.scala:230) [error] org.specs2.execute.AsResult$.apply(AsResult.scala:25) [error]
org.specs2.specification.core.Execution$$anonfun$withEnv$1.apply(Execution.scala:120) [error]
org.specs2.specification.core.Execution$$anonfun$withEnv$1.apply(Execution.scala:120) [error]
org.specs2.specification.core.Execution$$anonfun$execute$2$$anonfun$apply$2.apply(Execution.scala:70) [error]
org.specs2.specification.core.Execution$$anonfun$execute$2$$anonfun$apply$2.apply(Execution.scala:70) [error]
org.specs2.specification.core.Execution.setResult(Execution.scala:76) [error]
org.specs2.specification.core.Execution$$anonfun$execute$2.apply(Execution.scala:70) [error]
org.specs2.specification.core.Execution$$anonfun$execute$2.apply(Execution.scala:70) [error] scala.Option.fold(Option.scala:158) [error]
org.specs2.specification.core.Execution.execute(Execution.scala:70) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$executeFragment$1$$anonfun$apply$6.apply(Executor.scala:132) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$executeFragment$1$$anonfun$apply$6.apply(Executor.scala:130) [error]
org.specs2.specification.core.Fragment.updateExecution(Fragment.scala:44) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$executeFragment$1.apply(Executor.scala:130) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$executeFragment$1.apply(Executor.scala:129) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$sequencedExecution$1.executedFragment$lzycompute$1(Executor.scala:104) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$sequencedExecution$1.org$specs2$specification$process$DefaultExecutor$class$$anonfun$$executedFragment$1(Executor.scala:104) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$sequencedExecution$1$$anonfun$3.apply(Executor.scala:109) [error]
org.specs2.specification.process.DefaultExecutor$$anonfun$sequencedExecution$1$$anonfun$3.apply(Executor.scala:109) [error]
scalaz.concurrent.Task$$anonfun$delay$1.apply(Task.scala:272) [error] scalaz.concurrent.Task$$anonfun$delay$1.apply(Task.scala:272) [error] scalaz.concurrent.Task$$anonfun$suspend$1$$anonfun$4.apply(Task.scala:280) [error]
scalaz.concurrent.Task$$anonfun$suspend$1$$anonfun$4.apply(Task.scala:280) [error] scalaz.concurrent.Task$.Try(Task.scala:385) [error]
scalaz.concurrent.Task$$anonfun$suspend$1.apply(Task.scala:280) [error]
scalaz.concurrent.Task$$anonfun$suspend$1.apply(Task.scala:280) [error] scalaz.concurrent.Future.step(Future.scala:111) [error]
scalaz.concurrent.Future.listen(Future.scala:76) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:310) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:309) [error] scala.collection.Iterator$class.foreach(Iterator.scala:750) [error]
scala.collection.AbstractIterator.foreach(Iterator.scala:1202) [error] scala.collection.IterableLike$class.foreach(IterableLike.scala:72) [error] scala.collection.AbstractIterable.foreach(Iterable.scala:54) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:309) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:305) [error] scalaz.concurrent.Future.listen(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error] scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free.resume(Free.scala:73) [error]
scalaz.Free.go2$1(Free.scala:118) [error]
scalaz.Free.go(Free.scala:122) [error]
scalaz.Free.run(Free.scala:172) [error]
scalaz.concurrent.Future.listen(Future.scala:77) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:310) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:309) [error] scala.collection.Iterator$class.foreach(Iterator.scala:750) [error]
scala.collection.AbstractIterator.foreach(Iterator.scala:1202) [error] scala.collection.IterableLike$class.foreach(IterableLike.scala:72) [error] scala.collection.AbstractIterable.foreach(Iterable.scala:54) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:309) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:305) [error] scalaz.concurrent.Future.listen(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error] scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free.resume(Free.scala:73) [error]
scalaz.Free.go2$1(Free.scala:118) [error]
scalaz.Free.go(Free.scala:122) [error]
scalaz.Free.run(Free.scala:172) [error]
scalaz.concurrent.Future.listen(Future.scala:77) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:310) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:309) [error] scala.collection.Iterator$class.foreach(Iterator.scala:750) [error]
scala.collection.AbstractIterator.foreach(Iterator.scala:1202) [error] scala.collection.IterableLike$class.foreach(IterableLike.scala:72) [error] scala.collection.AbstractIterable.foreach(Iterable.scala:54) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:309) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:305) [error] scalaz.concurrent.Future.listen(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error]
scalaz.concurrent.Future$$anonfun$listen$1$$anonfun$apply$4.apply(Future.scala:80) [error] scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free$$anonfun$map$1.apply(Free.scala:52) [error]
scalaz.Free.resume(Free.scala:73) [error]
scalaz.Free.go2$1(Free.scala:118) [error]
scalaz.Free.go(Free.scala:122) [error]
scalaz.Free.run(Free.scala:172) [error]
scalaz.concurrent.Future.listen(Future.scala:77) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:310) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2$$anonfun$apply$10.apply(Future.scala:309) [error] scala.collection.Iterator$class.foreach(Iterator.scala:750) [error]
scala.collection.AbstractIterator.foreach(Iterator.scala:1202) [error] scala.collection.IterableLike$class.foreach(IterableLike.scala:72) [error] scala.collection.AbstractIterable.foreach(Iterable.scala:54) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:309) [error]
scalaz.concurrent.Future$$anon$1$$anonfun$reduceUnordered$2.apply(Future.scala:305) [error] scalaz.concurrent.Future.listen(Future.scala:80) [error]
scalaz.concurrent.Future.runAsync(Future.scala:143) [error]
scalaz.concurrent.Future.run(Future.scala:160) [error]
scalaz.concurrent.Task.attemptRun(Task.scala:104) [error]
org.specs2.control.ActionT$.fromTask(ActionT.scala:125) [error]
org.specs2.control.ActionTSupport$class.fromTask(ActionT.scala:188) [error]
org.specs2.control.package$Actions$.fromTask(package.scala:29) [error] org.specs2.reporter.Reporter$$anonfun$report$1.apply(Reporter.scala:47) [error]
org.specs2.reporter.Reporter$$anonfun$report$1.apply(Reporter.scala:37) [error]
org.specs2.runner.SbtRunner$$anonfun$specificationRun$1$$anonfun$2.apply(SbtRunner.scala:75) [error]
org.specs2.runner.SbtRunner$$anonfun$specificationRun$1$$anonfun$2.apply(SbtRunner.scala:75) [error]
org.specs2.control.ActionT$$anonfun$flatMap$1$$anonfun$apply$2.apply(ActionT.scala:36) [error]
org.specs2.control.ActionT$$anonfun$flatMap$1$$anonfun$apply$2.apply(ActionT.scala:36) [error]
org.specs2.control.StatusT$$anonfun$flatMap$1.apply(StatusT.scala:20) [error]
org.specs2.control.StatusT$$anonfun$flatMap$1.apply(StatusT.scala:19) [error] scala.Function1$$anonfun$andThen$1.apply(Function1.scala:55) [error] scalaz.WriterT$$anonfun$flatMapF$1.apply(WriterT.scala:63) [error] scalaz.WriterT$$anonfun$flatMapF$1.apply(WriterT.scala:62) [error]
scalaz.effect.IO$$anonfun$flatMap$1$$anonfun$apply$9.apply(IO.scala:62) [error]
scalaz.effect.IO$$anonfun$flatMap$1$$anonfun$apply$9.apply(IO.scala:61) [error]
scalaz.Free$$anonfun$flatMap$1$$anonfun$apply$1.apply(Free.scala:60) [error]
scalaz.Free$$anonfun$flatMap$1$$anonfun$apply$1.apply(Free.scala:60) [error] scalaz.Free.resume(Free.scala:72) [error]
scalaz.Free.go2$1(Free.scala:118) [error]
scalaz.Free.go(Free.scala:122) [error]
scalaz.Free.run(Free.scala:172) [error]
scalaz.effect.IO$class.unsafePerformIO(IO.scala:22) [error]
scalaz.effect.IOFunctions$$anon$6.unsafePerformIO(IO.scala:227) [error]
org.specs2.runner.SbtRunner$$anonfun$newTask$1$$anon$4.execute(SbtRunner.scala:40) [error] sbt.ForkMain$Run$2.call(ForkMain.java:294) [error]
sbt.ForkMain$Run$2.call(ForkMain.java:284) [error]
java.util.concurrent.FutureTask.run(FutureTask.java:266) [error]
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [error]
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [error] java.lang.Thread.run(Thread.java:745) [error] [error] [error] This looks like a specs2 exception... [error] Please report it with the preceding stacktrace at http://github.com/etorreborre/specs2/issues
One solution with basic user on application.conf
play.modules.enabled += "modules.DatabaseModule"
MyNameIs = {
database = {
driver = org.postgresql.Driver
url = "jdbc:postgresql://localhost:5432/databasename"
user = "postgreuser"
password = ""
numThreads = 10
connectionTimeout = 5000
validationTimeout = 5000
}
dispatcher {
fork-join-executor {
parallelism-factor = 2
parallelism-max = 20
}
}
on dir app you can create database module like this
import javax.inject.{Provider, Inject, Singleton}
import com.google.inject.AbstractModule
import com.typesafe.config.Config
import play.api.inject.ApplicationLifecycle
import play.api.{Configuration, Environment}
import slick.jdbc.JdbcBackend
import scala.concurrent.Future
class DatabaseModule(environment: Environment, configuration: Configuration)
extends AbstractModule {
override def configure(): Unit = {
bind(classOf[Config]).toInstance(configuration.underlying)
bind(classOf[slick.jdbc.JdbcBackend.Database]).toProvider(classOf[DatabaseProvider])
bind(classOf[models.UserDAO]).asEagerSingleton()
}
}
@Singleton
class DatabaseProvider @Inject() (config: Config, lifecycle: ApplicationLifecycle) extends Provider[slick.jdbc.JdbcBackend.Database] {
private val db = slick.jdbc.JdbcBackend.Database.forConfig("MyNameIs.database", config)
lifecycle.addStopHook { () =>
Future.successful(db.close())
}
override def get(): JdbcBackend.DatabaseDef = db
}
On app/models: UserDAO
import java.sql.Date
import javax.inject.{Inject, Singleton}
import com.typesafe.config.Config
import slick.driver.PostgresDriver.api._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
case class User(id: Option[Long] = None, name: String, firstname: String, email: String, password: String, birthday: Option[Date] = None, signDate: Option[Date] = Some(new Date(System.currentTimeMillis)))
@Singleton
class UserDAO @Inject()(config: Config, db: Database) {
private val users = TableQuery[Users]
override def delete(ids: Long*): Future[Boolean] = {
Future.sequence(for (id <- ids) yield {
db.run(users.filter(_.id === id).delete).map(_ == 1)
}).map {
_.find(i => i == false) == None
}
}
def insert(user: User): Future[Unit] = db.run(users += user).map{()}
override def update(obj: User): Future[Boolean] = ???
override def create(obj: User): Future[Boolean] = db.run(users += obj).map(_ == 1)
override def all: Future[Seq[User]] = db.run(users.result)
private class Users(tag: slick.lifted.Tag) extends Table[User](tag, "user") {
type S = String
type D = Date
type L = Long
// attribute name in table database
def id = column[L](ID, O.AutoInc, O.PrimaryKey)
def name = column[S](NAME)
def password = column[S](PASSWORD)
def firstname = column[S](FIRSTNAME)
def email = column[S](EMAIL)
def birthday = column[D](BIRTHDAY)
def signDate = column[D](SIGN_DATE)
override def * = (id.?, name, firstname, email, password, birthday.?, signDate.?) <> ((User.apply _)
.tupled, User.unapply _)
}
}
On controllers Application.scala
@Singleton
class Application @Inject()(userdao: UserDAO) extends Controller { code }
and on route file:
# Home page
GET / @controllers.Application.index
Working example for me:
application.conf
database {
dataSourceClass = org.postgresql.ds.PGSimpleDataSource
properties = {
databaseName = "some_db"
user = "local"
password = "local"
}
numThreads = 10
}
build.sbt
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.0.0",
"com.zaxxer" % "HikariCP" % "2.4.1",
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41",
// ...
)
And then I just call
Database.forConfig("database")
Using Java 7, Scala 2.11.6 and sbt 0.13.6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With