无法从结果集中获取行

unable to get the Row from ResultSet

以下函数将数据保存在cassandra中。它调用在同一 class 中定义的 abstract rowToModel 方法将从 cassandra 返回的数据转换为相应的数据模型。

def saveDataToDatabase(data:M):Option[M] = { //TODOM - should this also be part of the Repository trait?
    println("inserting in table "+tablename+" with partition key  "+partitionKeyColumns +" and values "+data)
    val insertQuery = insertValues(tablename,data)
    println("insert query is "+insertQuery)
    try {
      val resultSet:ResultSet = session.execute(insertQuery) //execute can take a Statement. Insert is derived from Statement so I can use Insert.
      println("resultset after insert: " + resultSet)
      println("resultset applied: " + resultSet.wasApplied())
      println(s"columns definition ${resultSet.getColumnDefinitions}")
      if(resultSet.wasApplied()){
        println(s"saved row ${resultSet.one()}")
        val savedData = rowToModel(resultSet.one())
        Some(savedData)
      } else {
        None
      }
    }catch {
      case e:Exception => {
        println("cassandra exception "+e)
        None
      }
    }
  }

abstractrowToModel定义如下

override def rowToModel(row: Row): PracticeQuestionTag = {
   PracticeQuestionTag(row.getLong("year"),row.getLong("month"),row.getLong("creation_time_hour"),
      row.getLong("creation_time_minute"),row.getUUID("question_id"),row.getString("question_description"))

  }

但是我在saveDataToDatabase中定义的打印语句没有打印数据。我原以为印刷品会打印 PracticeQuestionTag 但我看到的却是下面的

当我从 ResultSet 打印 one 时,我希望看到这样的结果 - PracticeQuestionTag(2018,6,1,1,11111111-1111-1111-1111-111111111111,some description1)。但是我看到的是

resultset after insert: ResultSet[ exhausted: false, Columns[[applied](boolean)]] resultset applied: true columns definition Columns[[applied](boolean)] saved row Row[true] row to Model called for row null cassandra exception java.lang.NullPointerException

为什么 ResultSetonecolumnDefinitions 没有向我显示数据模型中的值?

这是设计使然。插入的结果集将仅包含一行,用于说明结果是否已应用。

When executing a conditional statement, the ResultSet will contain a single Row with a column named “applied” of type boolean. This tells whether the conditional statement was successful or not.

这也很有意义,因为 ResultSet 应该 return 查询的结果,以及为什么要通过重新调整结果集中的所有输入来使结果集对象变重。可以找到更多详细信息 here

当然Get查询会有详细的结果集。