hashCode在spring数据cassandra的PrimaryKeyClass中的实现



我正在使用spring-data-cassandra,并且有一个这样的表其主要密钥是CCD_ 2。int_col1&int_col2是分区键bigint_col1&bigint_col2是集群密钥。

实施hashcode&equals方法。我上面的@PrimaryKeyClasshashcode实现应该是什么

// your class's constructor should have exactly four arguments
// and ensure that each of these four fields are non-null
@Override
public int hashCode() {
  return 37
    ^ int_col1.hashCode()
    ^ int_col2.hashCode()
    ^ bigint_col1.hashCode()
    ^ bigint_col2.hashCode();
}
@Override
public boolean equals(Object that) {
  if (this == that) {
    return true;
  }
  if (that == null) {
    return false;
  }
  if (!(that instanceof YourPrimaryKeyClass)) {
    return false;
  }
  YourPrimaryKeyClass other = (YourPrimaryKeyClass) that;
  return this.int_col1.equals(other.int_col1)
    && this.int_col2.equals(other.int_col2)
    && bigint_col1.equals(other.bigint_col1)
    && bigint_col2.equals(other.bigint_col2);
}

相关内容

  • 没有找到相关文章

最新更新