检索数据时出错,原因如下:。 org.apache.cassandra.serializers.MarshalException

时间:2016-05-12 13:34:20

标签: java jpa cassandra kundera

我在cassandra中有一个表,它有一个List类型的列, 当我尝试从该表中读取一行时,我发现在读取列表类型列时存在一些问题,如下所示:

27296 [Thread-15-localhostAMQPbolt0-executor[2 2]] INFO  c.i.c.c.CassandraClientBase - Returning cql query  INSERT INTO "sensors"("pressure","pieces","temperature","idsensor","date","event_time") VALUES(10.0,[{"idpiece":'1',"width":10.0,"height":11.0,"depth":12.0},{"idpiece":'2',"width":10.0,"height":11.0,"depth":12.0},{"idpiece":'3',"width":10.0,"height":11.0,"depth":12.0}],10.0,'1',33544,0) .
27319 [Thread-15-localhostAMQPbolt0-executor[2 2]] INFO  d.d.SensorDAOImpl - select p from sensors p
27498 [Thread-15-localhostAMQPbolt0-executor[2 2]] INFO  c.i.c.c.CassandraClientBase - Executing cql query SELECT * FROM "sensors" LIMIT 100.
27498 [Thread-15-localhostAMQPbolt0-executor[2 2]] INFO  c.i.c.c.CassandraClientBase - Executing query SELECT * FROM "sensors" LIMIT 100.
27745 [Thread-15-localhostAMQPbolt0-executor[2 2]] ERROR c.i.c.c.d.CassandraDataHandlerBase - Eror while retrieving data, Caused by: .
org.apache.cassandra.serializers.MarshalException: Unexpected extraneous bytes after list value
        at org.apache.cassandra.serializers.ListSerializer.deserializeForNativeProtocol(ListSerializer.java:104) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setElementCollectionList(CassandraDataHandlerBase.java:1727) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setElementCollection(CassandraDataHandlerBase.java:1568) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateViaThrift(CassandraDataHandlerBase.java:1154) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.onColumn(CassandraDataHandlerBase.java:1054) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateEntity(CassandraDataHandlerBase.java:653) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.CassandraClientBase$CQLClient.executeQuery(CassandraClientBase.java:2301) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.CassandraClientBase.executeSelectQuery(CassandraClientBase.java:926) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.thrift.ThriftClient.executeQuery(ThriftClient.java:1062) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.query.CassQuery.populateEntities(CassQuery.java:146) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.kundera.query.QueryImpl.fetch(QueryImpl.java:1377) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:200) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at database.dao.SensorDAOImpl.findByQuery(SensorDAOImpl.java:84) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at database.controller.DatabaseController.saveSensorEntitie(DatabaseController.java:47) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at connector.bolt.PrinterBolt.execute(PrinterBolt.java:66) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at org.apache.storm.daemon.executor$fn__8226$tuple_action_fn__8228.invoke(executor.clj:731) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.daemon.executor$mk_task_receiver$fn__8147.invoke(executor.clj:463) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.disruptor$clojure_handler$reify__7663.onEvent(disruptor.clj:40) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:435) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:414) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.disruptor$consume_batch_when_available.invoke(disruptor.clj:73) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.daemon.executor$fn__8226$fn__8239$fn__8292.invoke(executor.clj:851) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.util$async_loop$fn__554.invoke(util.clj:484) [storm-core-1.0.0.jar:1.0.0]
        at clojure.lang.AFn.run(AFn.java:22) [clojure-1.7.0.jar:?]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_99]
27753 [Thread-15-localhostAMQPbolt0-executor[2 2]] ERROR c.i.c.c.CassandraClientBase - Error while executing native CQL query Caused by {}.
javax.persistence.PersistenceException: org.apache.cassandra.serializers.MarshalException: Unexpected extraneous bytes after list value
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateEntity(CassandraDataHandlerBase.java:833) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.CassandraClientBase$CQLClient.executeQuery(CassandraClientBase.java:2301) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.CassandraClientBase.executeSelectQuery(CassandraClientBase.java:926) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.thrift.ThriftClient.executeQuery(ThriftClient.java:1062) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.query.CassQuery.populateEntities(CassQuery.java:146) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.kundera.query.QueryImpl.fetch(QueryImpl.java:1377) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:200) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at database.dao.SensorDAOImpl.findByQuery(SensorDAOImpl.java:84) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at database.controller.DatabaseController.saveSensorEntitie(DatabaseController.java:47) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at connector.bolt.PrinterBolt.execute(PrinterBolt.java:66) [Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at org.apache.storm.daemon.executor$fn__8226$tuple_action_fn__8228.invoke(executor.clj:731) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.daemon.executor$mk_task_receiver$fn__8147.invoke(executor.clj:463) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.disruptor$clojure_handler$reify__7663.onEvent(disruptor.clj:40) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:435) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.utils.DisruptorQueue.consumeBatchWhenAvailable(DisruptorQueue.java:414) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.disruptor$consume_batch_when_available.invoke(disruptor.clj:73) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.daemon.executor$fn__8226$fn__8239$fn__8292.invoke(executor.clj:851) [storm-core-1.0.0.jar:1.0.0]
        at org.apache.storm.util$async_loop$fn__554.invoke(util.clj:484) [storm-core-1.0.0.jar:1.0.0]
        at clojure.lang.AFn.run(AFn.java:22) [clojure-1.7.0.jar:?]
        at java.lang.Thread.run(Thread.java:745) [?:1.7.0_99]
Caused by: org.apache.cassandra.serializers.MarshalException: Unexpected extraneous bytes after list value
        at org.apache.cassandra.serializers.ListSerializer.deserializeForNativeProtocol(ListSerializer.java:104) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setElementCollectionList(CassandraDataHandlerBase.java:1727) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setElementCollection(CassandraDataHandlerBase.java:1568) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateViaThrift(CassandraDataHandlerBase.java:1154) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.onColumn(CassandraDataHandlerBase.java:1054) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        at com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateEntity(CassandraDataHandlerBase.java:653) ~[Zorro-0.0.1-SNAPSHOT-jar-with-dependencies.jar:?]
        ... 19 more

但保存数据没有任何问题。

以下是实体经理的创建方式:

Map propertyMap = new HashMap();
 propertyMap.put(CassandraConstants.CQL_VERSION, CassandraConstants.CQL_VERSION_3_0);
 EntityManagerFactory emf = Persistence.createEntityManagerFactory("cassandra_pu", propertyMap);
EntityManager em = emf.createEntityManager();

以下是关于cassandra的信息:

  

[cqlsh 5.0.1 | Cassandra 2.1.12 | CQL规范3.2.1 |原生协议v3]

<dependency>
            <groupId>com.impetus.kundera.client</groupId>
            <artifactId>kundera-cassandra</artifactId>
            <version>3.4</version>
        </dependency>

1 个答案:

答案 0 :(得分:0)

我通过安装cassandra 3.4并使用自动模式生成解决了这个问题。

我在我的resources / META-INF / persistence.xml文件中添加了这一行

<property name="kundera.ddl.auto.prepare" value="create" />