首页 > 解决方案 > 使用最新版本的 phantom(2.42.0) 和 scala(2.12.0-RC2) 查询数据库时未找到参数 ev:Nothing 的隐式

问题描述

我正在升级到最新版本的 phantom-dsl 2.42.0 和 scala 2.12,根据迁移指南,我现在不需要生成 fromRow() 方法,但是在查询数据库时我没有找到隐式参数(编译时间)。

我尝试编写 fromRow 方法,但仍然没有用

我的案例课程是-

case class Ball(matchId: Int,
                      inningsid: Int,
                      ballNbr: Int,
                      timeScore: Long,
                      batStrikerDots: Option[Int],
                      batStrikerFours: Option[Int],
                      commFormats: Map[String, CommentaryFormats],
                      .......
                      ......)

class Ball extends Table[BallData, Ball] with CassandraSession with CommentaryPrimitive {

object matchId extends IntColumn with PartitionKey {
    override lazy val name = col_name
  }

  object inningsId extends IntColumn with PrimaryKey with ClusteringOrder with Descending {
    override lazy val name = col_name
  }

  object ballNbr extends IntColumn with PrimaryKey with ClusteringOrder with Descending {
    override lazy val name = col_name
  }

  object timeScore extends DateTimeColumn with PrimaryKey with ClusteringOrder with Descending {
    override lazy val name = col_name
  }

object commentaryFormat extends MapColumn[String, CommentaryFormats] {
    override lazy val name = "comm_format"
  }

............
............

}

col_name 是各自的列名。

其中 comm_format 是 UDT,所以我定义了 CommentaryPrimitive,它注册了一个关于如何将 cassandra 数据反序列化为 scala 案例类的编解码器,而 CassandaraSession 提供了隐式密钥空间和会话。

这是我注册编解码器的原始代码 -

override def cassandraType: String = {

            val format_types = CassandraConnector.getSession.getCluster.getMetadata.getKeyspace("matches_data").getUserType("format_types")
            val formatCodecCodec = new CommentaryCodec(TypeCodec.userType(format_types), classOf[CommentaryFormats])

        CassandraConnector.registerCodec(formatCodecCodec)

            format_types.toString()
        }

override def asCql(value: PrimitiveType): String = ???

        override def dataType: String = ???

        override def serialize(obj: PrimitiveType, protocol: ProtocolVersion): ByteBuffer = ???

        override def deserialize(source: ByteBuffer, protocol: ProtocolVersion): PrimitiveType = ??? 

但是在查询时我无法解决这个问题-

select.where(_.matchId eqs matchId)(...).one()(...) --> 检索 Ball 对象

... ->未找到隐式

使用新版本的 phantom-dsl 它应该会自动解析 Ball 数据,但它会抛出错误,没有找到隐式。

标签: javascalacassandradatastaxphantom-dsl

解决方案


推荐阅读