首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >幻影生成的` throws‘方法在运行时抛出一个ClassCastException

幻影生成的` throws‘方法在运行时抛出一个ClassCastException
EN

Stack Overflow用户
提问于 2017-05-15 15:28:48
回答 1查看 165关注 0票数 0

我有以下幻影表定义:

代码语言:javascript
复制
package myPackage

import com.outworkers.phantom.CassandraTable
import com.outworkers.phantom.connectors.RootConnector
import com.outworkers.phantom.dsl._
import com.outworkers.phantom.keys.{PartitionKey, PrimaryKey}

import scala.concurrent.Future

case class KeysTwoThreeAndFour(myKeyTwo: Int, myKeyThree: String, myKeyFour: Int)

abstract class MyTable extends CassandraTable[MyTable, Int] with RootConnector {
  object myKeyOne extends IntColumn(this) with PartitionKey
  object myKeyTwo extends IntColumn(this) with PrimaryKey
  object myKeyThree extends StringColumn(this) with PrimaryKey
  object myKeyFour extends IntColumn(this) with PrimaryKey
  object myValue extends IntColumn(this)

  def insertValue(myKeyOne: Int, valuesMap: Map[KeysTwoThreeAndFour, Int]): Future[Unit] = {
    val resultFutures = for ((key: KeysTwoThreeAndFour, myValue) <- valuesMap) yield {
      store(myKeyOne, key.myKeyTwo, key.myKeyThree, key.myKeyFour, myValue).future()
    }


    Future.sequence(resultFutures).map { _ => () }
  }
}

这编译得很好,但在运行时抛出以下异常:

代码语言:javascript
复制
java.lang.ClassCastException: scala.Tuple5 cannot be cast to scala.runtime.Nothing$
    at myPackage.MyTable$anon$macro$1$1.store(MyTable.scala:10)
    at com.outworkers.phantom.CassandraTable.store(CassandraTable.scala:125) ~[com.outworkers.phantom-dsl_2.11-2.7.6.jar:2.7.6]
    at myPackage.MyTable$$anonfun$2.apply(MyTable.scala:19)
    at myPackage.MyTable$$anonfun$2.apply(MyTable.scala:18)
    ...

我正在效仿幻影表文档的底部的例子,问题似乎是什么?问题是我有一个简单的Int作为我的“记录”类型而不是一个实际的类吗?

我使用的是phantom-dsl 2.7.6、Play Framework2.3.10和Scala2.11.11。

请注意,以下代码工作正常:

代码语言:javascript
复制
insert
.value(_.myKeyOne, myKeyOne)
.value(_.myKeyTwo, key.myKeyTwo)
.value(_.myKeyThree, key.myKeyThree)
.value(_.myKeyFour, key.myKeyFour)
.value(_.myValue, myValue)
.future()

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-16 08:48:25

这个问题似乎是由于"Record“类型是一个原语,而不是一个类;换句话说,将我的Int封装在一个用该Int作为唯一成员解决问题的案例类中。

此外,Select语句也有一个问题,该问题也得到了解决:

代码语言:javascript
复制
java.util.concurrent.ExecutionException: Boxed Error
    at com.outworkers.phantom.CassandraTable.fromRow(CassandraTable.scala:85) ~[com.outworkers.phantom-dsl_2.11-2.7.6.jar:2.7.6]
    at com.outworkers.phantom.SelectTable$$anonfun$select$1.apply(SelectTable.scala:24) ~[com.outworkers.phantom-dsl_2.11-2.7.6.jar:2.7.6]
    at com.outworkers.phantom.SelectTable$$anonfun$select$1.apply(SelectTable.scala:24) ~[com.outworkers.phantom-dsl_2.11-2.7.6.jar:2.7.6]
    at com.outworkers.phantom.builder.query.SelectQuery.fromRow(SelectQuery.scala:59) ~[com.outworkers.phantom-dsl_2.11-2.7.6.jar:2.7.6]
    at com.outworkers.phantom.builder.query.RootExecutableQuery$class.singleResult(ExecutableQuery.scala:176) ~[com.outworkers.phantom-dsl_2.11-2.7.6.jar:2.7.6]
    at com.outworkers.phantom.builder.query.SelectQuery.singleResult(SelectQuery.scala:33) ~[com.outworkers.phantom-dsl_2.11-2.7.6.jar:2.7.6]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43983350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档