1

Now, I'm writing sample for learning scala slick. I'm using some github projs and stackoverflow (Q&A)s. Below my sample code:

import scala.slick.driver.PostgresDriver.simple._
import Database.threadLocalSession


object TestApp extends App{

  case class MyTable(id: Option[Int], foo: String, bar: String) 

  object MyTables extends Table[MyTable]("mytable") { 
    def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
    def foo = column[String]("foo", O.NotNull) 
    def bar = column[String]("bar", O.NotNull) 
    def * = id.?  ~ foo ~ bar <> (MyTable, MyTable.unapply _)
    def forInsert = foo ~ bar <>
        ({ (f, l) => MyTable (None, f, l) }, { ep:MyTable => Some((ep.foo, ep.bar)) })
        val findByID = createFinderBy(_.id)
   } 

    implicit val session = Database.forURL("jdbc:postgresql://localhost:5432/myserver",
                         driver="org.postgresql.Driver",
                         user="myadmin",
                         password="myadmin") 
    session withTransaction {
      MyTables.ddl.create
        MyTables.foo ~ MyTables.bar).insert("Homer", "Simpson")
      MyTables.forInsert.insertAll(
        MyTable(None, "Marge", "Bouvier"),
        MyTable(None, "Carl", "Carlson"),
        MyTable(None, "Lenny", "Leonard")
      )
    }

}

EXCEPTION:

Exception in thread "main" java.lang.NoClassDefFoundError: scala/Right at scala.slick.driver.BasicProfile$class.createQueryTemplate(BasicProfile.scala:12) at scala.slick.driver.PostgresDriver$.createQueryTemplate(PostgresDriver.scala:69) at scala.slick.ql.Parameters.flatMap(Parameters.scala:9) at scala.slick.driver.BasicTableComponent$Table.createFinderBy(BasicTableComponent.scala:30) at TestApp$MyTables$.(TestApp.scala:16)

Create table in postgresql

CREATE TABLE mytable
(
    id            serial primary key,
    foo           VARCHAR(40) not null,
    bar           VARCHAR(40) not null,
);

I'm using this tools and libraries:

  1. Scala IDE - 2.10
  2. Java version - 1.7.0_11
  3. slick_2.10.0-M4-0.10.0-M2.jar
  4. postgresql-9.2-1003-jdbc4.jar
  5. Database - PostgreSQL 8.3

What's Wrong Here? Thanks in advance.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
Bob
  • 1,351
  • 11
  • 28
  • 1
    A few remarks: Database.forURL returns a Database object, not a Session. It does not need to be implicit. Also, it is adviced to remove the `threadLocalSession` import and instead use `withTransaction{ implicit session => ... }`. Besides that, the code you show does not compile. There is an unopened parenthesis in `MyTables.foo ~ MyTables.bar).insert("Homer", "Simpson")` and you probably want to do this: `Query(MyTables).map(r=>(r.foo,r.bar)).insert(("Homer","Simpson"))` – cvogt Nov 06 '13 at 06:16
  • My guess here configuration problem. – Bob Nov 06 '13 at 07:24
  • In Scala 2.10 does not exist scala/Right, it has scala.util.Right. – Bob Nov 06 '13 at 07:26

0 Answers0