Search code examples
cassandrakundera

Kundera Cassandra - mapping a map


In my cassandra (V 3.0.1) schema i have a column with map type. Column-family:

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

I use Kundera (V3.2) with the com.impetus.client.cassandra.thrift.ThriftClientFactory and my Test entity looks like this:

@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;

}

When I want to query the data from the Test table via

EntityManager manager = entityManagerFactory.createEntityManager(getProperties());
result = new manager.find(Test.class, id); 

I receive the error that the map cannot be mapped.

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]

Does anybody no where the problem is? I use CQL Version 3 and other entities without a map column are working.


Solution

  • I found a solution for this problem. When using Cassandra 2.2 instead of 3.0 and changing the private Map<String, BigDecimal> targetMisc; to private Map<String, Double> targetMisc; then the mapping works correctly.

    It seams there Kundera 3.2 does have a problem with the version 3 of Cassandra. Kundera uses the cassandra-driver-core-2.1.5.jar and referring to this http://docs.datastax.com/en/developer/driver-matrix/doc/common/driverMatrix.html?scroll=driverMatrix__driver-cmpt-matrix there is no compatibility with that version of the java driver.

    EDIT: Here (Kundera compatibility with Cassandra 3.0.1) you can see that Kundera 2.2 does not have a full support for Cassandra 3.*