问题
I have a table in cassandra which has a column of type MAP (i.e) source_id_map map
When I try to read a row from this table, I see that there is some issue while reading column of map type as below
Caused by: javax.persistence.PersistenceException: org.apache.cassandra.serializers.MarshalException: Unexpected extraneous bytes after map value at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setCollectionValue(CassandraDataHandlerBase.java:2526) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setFieldValueViaCQL(CassandraDataHandlerBase.java:1504) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateViaThrift(CassandraDataHandlerBase.java:1163) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.onColumn(CassandraDataHandlerBase.java:1054) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateEntity(CassandraDataHandlerBase.java:653)
Another exception that I notice is as below.
Error while retrieving fieldUTF8Type value via CQL, Caused by: . java.lang.IllegalArgumentException at java.nio.Buffer.limit(Buffer.java:267) at org.apache.cassandra.utils.ByteBufferUtil.readBytes(ByteBufferUtil.java:543) at org.apache.cassandra.utils.ByteBufferUtil.readBytesWithShortLength(ByteBufferUtil.java:552) at org.apache.cassandra.serializers.CollectionSerializer.readValue(CollectionSerializer.java:128) at org.apache.cassandra.serializers.MapSerializer.deserializeForNativeProtocol(MapSerializer.java:104) at com.impetus.client.cassandra.schemamanager.CassandraDataTranslator$MapTypeBuilder.decompose(CassandraDataTranslator.java:1177) at com.impetus.client.cassandra.schemamanager.CassandraDataTranslator$MapTypeBuilder.access$4800(CassandraDataTranslator.java:1100) at com.impetus.client.cassandra.schemamanager.CassandraDataTranslator.decompose(CassandraDataTranslator.java:507) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setCollectionValue(CassandraDataHandlerBase.java:2518) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setFieldValueViaCQL(CassandraDataHandlerBase.java:1504) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateViaThrift(CassandraDataHandlerBase.java:1163) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.onColumn(CassandraDataHandlerBase.java:1054) at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateEntity(CassandraDataHandlerBase.java:653) at com.impetus.client.cassandra.CassandraClientBase$CQLClient.executeQuery(CassandraClientBase.java:2272) at com.impetus.client.cassandra.CassandraClientBase.executeSelectQuery(CassandraClientBase.java:926) at com.impetus.client.cassandra.thrift.ThriftClient.executeQuery(ThriftClient.java:1062) at com.impetus.client.cassandra.query.CassQuery.populateEntities(CassQuery.java:153) at com.impetus.kundera.query.QueryImpl.fetch(QueryImpl.java:1377) at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:200)
回答1:
Please enable CQL3 both while inserting as well as reading data
Map propertyMap = new HashMap();
propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra-pu",propertyMap);
来源:https://stackoverflow.com/questions/35836693/caused-by-javax-persistence-persistenceexception-org-apache-cassandra-serializ