postgresql - 斯卡拉.slick.SlickException : JdbcProfile has no JdbcType for type UnassignedType - on Option fields

标签 postgresql scala exception mapping slick

我通过扩展表的类成功地将不带可选字段的案例类映射到 Postgres 数据库。 现在我需要使用带有 Optional[String] 和 Optional[DateTime] 字段的案例类。

我已经找到了如何为其声明映射:

case class Issue(id: Int,
  key: String,
...
  resolutionName: Option[String],
  resolutionDate: Option[DateTime],
             )

case class Issues(tag: Tag) extends Table[Issue](tag, "Issues") {
// This is the primary key column:
  def id = column[Int]("id", O.PrimaryKey)
  def key = column[String]("key")
... 
  def resolutionName = column[String]("resolutionName")
  def resolutionDate = column[DateTime]("resolutionDate")

  def * = (id, key, resolutionName.?, resolutionDate.?) <> (Issue.tupled, Issue.unapply)
}

代码编译良好,但在运行时出现异常:

Exception in thread "main" scala.slick.SlickException: JdbcProfile has no JdbcType for type UnassignedType
    at scala.slick.driver.JdbcTypesComponent$class.jdbcTypeFor(JdbcTypesComponent.scala:66)
    at scala.slick.driver.PostgresDriver$.jdbcTypeFor(PostgresDriver.scala:151)
    at scala.slick.driver.JdbcTypesComponent$JdbcType$.unapply(JdbcTypesComponent.scala:49)

我该怎么做才能让它发挥作用?

最佳答案

列也必须定义为 Option:

def resolutionName = column[Option[String]]("resolutionName")
def resolutionDate = column[Option[DateTime]]("resolutionDate")

您还可以避免投影函数中的 .?,因为该值已经映射为选项:

def * = (id, key, resolutionName, resolutionDate) <> (Issue.tupled, Issue.unapply)

关于postgresql - 斯卡拉.slick.SlickException : JdbcProfile has no JdbcType for type UnassignedType - on Option fields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24480788/

相关文章:

Postgresql order by - 扩展了丹麦语字符

java - 对数据库进行 9 次查询后,执行相同查询的时间乘以 7

java - 为什么我会收到 ArrayIndexOutOfBoundsException?

c++ - 设置终止和意外处理程序

C++ STL 的 copy() 异常安全

sql - 根据另一个表中的值更新 2 列

php - postgresql - 当用户名用base64编码时如何进行查询搜索?

scala - Spark的RangePartitioner中的sketch方法在做什么

scala - reduceByKey(_++ _) 是什么意思

Scala应用程序结构