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