Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't read Integer column using Anorm

Tags:

scala

anorm

When I try to run (from Play Framework):

import play.api.db.DB
import anorm._
import org.joda.time.DateTime
import AnormExtensions._ // http://stackoverflow.com/a/11975107/11236
import play.api.Play.current
import java.util.Date

var stream = SQL("SELECT amiId, created, version FROM Amis WHERE created = {maxCreated}")
    .on("maxCreated" -> new Date(maxCreated.getMillis))
    .apply()

val map: Stream[Ami] = stream.map { ami =>
    val s: String = ami[String]("amiId")
    val date: Date = ami[Date]("created")

    // The following line throws a compilation error
    var version: Integer = ami[Integer]("version")

    new Ami(s, new DateTime(date), version)
}

I get a compilation error : could not find implicit value for parameter c: anorm.Column[Integer]

What's the problem here? If I can read a Date, why can't I read an Integer?

like image 896
ripper234 Avatar asked Nov 02 '22 22:11

ripper234


1 Answers

The problem was that I used java java.lang.Integer instead of scala.Int.

like image 122
ripper234 Avatar answered Nov 13 '22 02:11

ripper234