Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MappedColumnType:当MySQL列定义为选项[String]-ergo nullable时,将字符串转换为向量[String]_Mysql_Scala_Slick - Fatal编程技术网

MappedColumnType:当MySQL列定义为选项[String]-ergo nullable时,将字符串转换为向量[String]

MappedColumnType:当MySQL列定义为选项[String]-ergo nullable时,将字符串转换为向量[String],mysql,scala,slick,Mysql,Scala,Slick,我的目标是用向量[String]填充Slick实体的filters变量,该向量是通过解析MySQL的filters列中存储的字符串生成的 我拥有的Slick和MySQL表定义的简化版本如下: object Something { class Something(tag: Tag) extends Table[SomethingRow](tag, "SOMETHING") { def filters = column[Vector[String]]("FILTERS")

我的目标是用
向量[String]
填充Slick实体的
filters
变量,该向量是通过解析MySQL的filters列中存储的
字符串生成的

我拥有的Slick和MySQL表定义的简化版本如下:

object Something {

    class Something(tag: Tag) extends Table[SomethingRow](tag, "SOMETHING") {

        def filters = column[Vector[String]]("FILTERS")

        override def * = (filters).mapTo[SomethingRow]
    }

}
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[SlickException: Read NULL value (null) for ResultSet column <computed>]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:255)
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:182)
    at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:310)
用于映射db行的case类是:

case类SomethingRow(过滤器:Vector[String])
为了启用此转换,我定义了以下隐式:

隐式val stringToVectorMapper=MappedColumnType.base[Vector[String],String](
{vctr=>
如果(vctr==null | | vctr.isEmpty)StringUtils.EMPTY
else vctr.mkString(“,”)
},
{str=>
if(StringUtils.isEmpty(str))Vector.empty
else str.split(“,”).toVector
})
我将其导入
Something
类和相应的存储库中

我得到的错误如下:

object Something {

    class Something(tag: Tag) extends Table[SomethingRow](tag, "SOMETHING") {

        def filters = column[Vector[String]]("FILTERS")

        override def * = (filters).mapTo[SomethingRow]
    }

}
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[SlickException: Read NULL value (null) for ResultSet column <computed>]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:255)
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:182)
    at play.core.server.AkkaHttpServer$$anonfun$2.applyOrElse(AkkaHttpServer.scala:310)
我收到一个“未找到”错误:

No implicits found for evidence: MySQLProfile.BaseColumnType[Option[String]]

我通过添加一个空的
字符串
作为数据库中
过滤器
列的默认值来解决这个问题,这样它就不会为null,但这不是一个解决方案。问题仍然存在:如何为可为空的db列定义灵活的自定义数据类型。我解决了这个问题,添加了一个空的
String
作为数据库中
filters
列的默认值,这样它就不会为空,但这不是一个解决方案。问题仍然存在:如何为可为空的db列定义灵活的自定义数据类型。