Slick 3.1.1 throws "IllegalArgumentException: Unknown field" on autoInc insertion

11 views
Skip to first unread message

Michael Slinn

unread,
Jul 26, 2016, 3:45:38 PM7/26/16
to Slick / ScalaQuery
I have a Postgres table that has a key defined like this:

id BIGSERIAL PRIMARY KEY

Other tables have keys defined exactly the same. This table, however, throws "java.lang.IllegalArgumentException: Unknown field: id" when autoInc is invoked. Not sure what makes this table different. The database record does get written, however, even though an exception is thrown.

Here is a simplified version of the code:

class CourseTable(tag: Tag) extends Table[Course](tag, "courses") {
  // ...
  def id = column[Option[Id]]("id", O.PrimaryKey, O.AutoInc)
  // ...
}

val sanitize = (course: Course) => {
  course.copy( /* blah blah */ )
}

// Type Course has a public property id of type Id
val course: Course = ??? // constructor details are irrelevant

val copyUpdate = (course: Course, id: Option[Id]) => sanitize(course)
lazy val queryAll = TableQuery[CourseTable]
def autoInc = queryAll returning queryAll.map(_.id) into copyUpdate
database.run(autoInc +=
course) // Boom!

Suggestions?

Mike

Reply all
Reply to author
Forward
0 new messages