1

I'm getting a class cast exception in this script and I simply cannot get why. The error is:

java.lang.ClassCastException: java.sql.Timestamp cannot be cast to scala.Product

here's my code:

import java.sql.Timestamp
import scala.slick.driver.MySQLDriver.simple._
import scala.slick.collection.heterogenous._
import syntax._
import org.joda.time.DateTime
import db.DealDAO
import DateTimeImplicits._

// Implicitly convert DateTime to Timestamp (and it seems to work)
object DateTimeImplicits {
   implicit def DateTime2Timestamp(value : DateTime) = new Timestamp(value.getMillis) 
}

object TryHList {

  class Tests(tag: Tag) extends Table[Timestamp :: HNil](tag, "tests") {
    def timeCol = column[Timestamp]("time_col")
    def * = (timeCol :: HNil)
  }

  def tests = TableQuery[Tests]

  def createTable = DealDAO.db.withSession { implicit session =>
    tests.ddl.create
  }

  def insert(dt: DateTime) = DealDAO.db.withSession { implicit session =>
    tests += (dt :: HNil)
  }

}

object Main {

  def main(args: Array[String]): Unit = {
  //  TryHList.createTable
     TryHList.insert(new DateTime())
  }
}
Max
  • 2,508
  • 3
  • 26
  • 44

1 Answers1

2

You uncovered a bug in Slick when using a 1-element HList. I submitted a fix for 2.0.1 (RC1 will probably arrive end of next week): https://github.com/slick/slick/pull/658

Unrelated: If you don't already know about it, check out https://github.com/tototoshi/slick-joda-mapper

cvogt
  • 11,260
  • 30
  • 46