我正在使用spring-data-cassandra
,并有一个表格
它的主键是((int_col1,int_col2),bigint_col1,bigint_col2)
。
int_col1
& int_col2
是分区键
bigint_col1
& bigint_col2
是群集密钥。
实施hashcode
&的重要性我班级的equals
方法。
上述hashcode
@PrimaryKeyClass
实施应该是什么
答案 0 :(得分:1)
// 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);
}