读取列/列表(Scala)时出现Astyanax / Cassandra InstantiationException

时间:2012-09-11 05:36:31

标签: scala cassandra astyanax

在这个上坚持了好几个小时!非常感谢任何见解:)

  • Scala 2.9.2
  • Astyanax 1.0.6(也试过1.0.5)
  • Cassandra 1.1.4
  • 使用CompositeRowKey,CompositeColumnName
  • 插入Cassandra没问题
  • 可以读取一行,ColumnList.size()返回正确的计数但是任何访问ColumnList的尝试(即迭代,访问迭代ColumnList,getColumnByIndex(),getColumnByName()等)都会抛出以下异常:

例外:

java.lang.RuntimeException:java.lang.InstantiationException

相关的堆栈跟踪:

java.lang.RuntimeException: java.lang.InstantiationException: shops.integration.db.scalaquery.ReportingDao$MetricsLogFileCompositeColumn
        at com.netflix.astyanax.serializers.AnnotatedCompositeSerializer.fromByteBuffer(AnnotatedCompositeSerializer.java:136)
        at com.netflix.astyanax.serializers.AbstractSerializer.fromBytes(AbstractSerializer.java:40)
        at com.netflix.astyanax.thrift.model.ThriftColumnOrSuperColumnListImpl.constructMap(ThriftColumnOrSuperColumnListImpl.java:201)
        at com.netflix.astyanax.thrift.model.ThriftColumnOrSuperColumnListImpl.getColumn(ThriftColumnOrSuperColumnListImpl.java:189)
        at com.netflix.astyanax.thrift.model.ThriftColumnOrSuperColumnListImpl.getColumnByName(ThriftColumnOrSuperColumnListImpl.java:103)

具体做法是:

at java.lang.Class.newInstance0(Class.java:357)
at java.lang.Class.newInstance(Class.java:325)
at com.netflix.astyanax.serializers.AnnotatedCompositeSerializer.createContents(AnnotatedCompositeSerializer.java:167)

相关示例代码:

class TestCompositeColumn(@(Component @field) var logFileId: Long, @(Component @field) var dt: String, @(Component @field) var dk: String) extends Ordered[TestCompositeColumn] {
    def this() = this(0l, "", "")
    //equals, hashCode, compare all implemented
}

我也在课堂上尝试过这种变化:

class TestCompositeColumn(idIn: Long, key1In: String, key2In: String) extends Ordered[TestCompositeColumn] {
    @Component(ordinal = 0) var id: Long = idIn
    @Component(ordinal = 1) var key1: String = key1In
    @Component(ordinal = 2) var key2: String = key2In

    def this() = this(0, null, null)
    //equals, hashCode, compare all implemented
}

val TEST_COLUMN_FAMILY = new ColumnFamily[TestRowKey, TestCompositeColumn](
    "test_column_family",
    new AnnotatedCompositeSerializer[TestRowKey](classOf[TestRowKey]),
    new AnnotatedCompositeSerializer[TestCompositeColumn](classOf[TestCompositeColumn]),
    BytesArraySerializer.get());

var columnList = keyspace.prepareQuery(TEST_COLUMN_FAMILY)
    .getKey(TestRowKey(1l, 2012090100))
    .execute().getResult()

    // OK - will return 6 for example, also verified via cassandra-cli
    println(columnList.size())         

    // ERROR - will throw exception above.  Iterating, or any type of access will also throw same exception
    println(columnList.getColumnByIndex(0).getStringValue())  

1 个答案:

答案 0 :(得分:3)

事实证明,TestCompositeColumn不能被定义为内部类。