Kundera Cassandra - 绘制地图

时间:2016-01-25 15:39:43

标签: cassandra kundera

在我的cassandra(V 3.0.1)架构中,我有一个带有地图类型的列。 列家族:

CREATE TABLE test.Test (
  id uuid,
  targetMisc map<text, double>,
  PRIMARY KEY (id));

我使用带有com.impetus.client.cassandra.thrift.ThriftClientFactory的Kundera(V3.2),我的Test实体看起来像这样:

@Entity
@Table(name="test")
public class Test implements Serializable {

    private static final long serialVersionUID = -7665632851374123059L;

    @Id
    @Column
    private UUID id;


    @Column(name="targetmisc")
    private Map<String, BigDecimal> targetMisc;

}

当我想通过

查询Test表中的数据时
EntityManager manager = entityManagerFactory.createEntityManager(getProperties());
result = new manager.find(Test.class, id); 

我收到无法映射地图的错误。

Stacktrace:

16:26:34.165 [http-bio-8080-exec-3] ERROR e5bc0aec-802b-459f-a24e-675037811135 com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase - Error while setting fieldtargetMisc value via CQL, Caused by:
org.apache.cassandra.serializers.MarshalException: Unexpected extraneous bytes after map value
at org.apache.cassandra.serializers.MapSerializer.deserializeForNativeProtocol(MapSerializer.java:109) ~[cassandra-all-2.2.2.jar:2.2.2]

有人没有问题吗?我使用的是CQL Version 3,其他没有map列的实体正在使用。

1 个答案:

答案 0 :(得分:1)

我找到了解决这个问题的方法。使用Cassandra 2.2而不是3.0并将private Map<String, Double> targetMisc;更改为cassandra-driver-core-2.1.5.jar时,映射可以正常工作。

它接缝在那里Kundera 3.2确实与Cassandra版本3有问题。 Kundera使用package dan.cielos; import android.widget.CompoundButton; import android.os.Bundle; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.MultiAutoCompleteTextView; import android.app.Activity; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; import android.widget.ToggleButton; import android.widget.TextView; import android.widget.NumberPicker; public class MainActivity extends AppCompatActivity { //private private int min = 1; private int max = 100; private TextView txt; /*public boolean recurse(boolean toggle) { if (toggle == false) { return false; } else { return recurse(toggle); } }*/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_random); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); NumberPicker np = (NumberPicker) findViewById(R.id.numPick); final TextView rn = (TextView) findViewById(R.id.random_number); final ToggleButton tog = (ToggleButton) findViewById(R.id.random_button); np.setMinValue(min); np.setMaxValue(max); toolbar.setTitle("Random Number"); setSupportActionBar(toolbar); tog.setOnClickListener(new OnClickListener() { public void onClick(View v){ //recurse(tog.isChecked()); if (tog.isChecked()) {//the result i want to achieve is while the toggle button is on, iteratively generate numbers until user press the toggle button again double ran = Math.random() * (max -min) + min; ran = Math.round(ran); rn.setText(Double.toString(Math.floor(ran))); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } 并引用此http://docs.datastax.com/en/developer/driver-matrix/doc/common/driverMatrix.html?scroll=driverMatrix__driver-cmpt-matrix,与该版本的java驱动程序不兼容。

编辑:在这里(Kundera compatibility with Cassandra 3.0.1)你可以看到昆德拉2.2并没有完全支持卡桑德拉3。*