简体   繁体   中英

No Implicit session available Scala Slick

   import scala.slick.driver.PostgresDriver.simple._
   import scala.slick.session.Database.threadLocalSession
   object Main extends App {
         Database.forURL("jdbc:postgresql://localhost:5432/slick", driver =
           "org.postgresql.Driver",user="postgres",password="postgres") withSession { } ;
      } 

What am I suppose to fill in the "withSession" parameter. I am trying to follow the slick tutorial here , but with postgres.

Here is my error stack:

> run
[info] Running Main 
[error] (run-main) java.sql.SQLException: No implicit session available; threadLocalSession can only be used within a withSession block
java.sql.SQLException: No implicit session available; threadLocalSession can only be used within a withSession block
    at scala.slick.session.Database$.threadLocalSession(Database.scala:74)
    at Main$delayedInit$body.apply(main.scala:9)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at Main$.main(main.scala:4)
    at Main.main(main.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
    at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 0 s, completed Sep 19, 2013 3:38:34 PM

Thanks!

withSession is where your queries go. They need a session. Also please remove the threadLocalSession import and instead write

withSession{ implicit session:Session => 
  // <- your queries here    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM