Kundera Cassandra JPQL with Compound Key

ε祈祈猫儿з 提交于 2019-12-23 04:18:16

问题


Am using Kundera JPA for Cassandra. Kundera version is: 3.8

Here are my Entity definitions:-

@Embeddable
public class PartitionKey implements Serializable
{
    @Column(name = "ID")
    private String Id;

    @Column (name = "TYPE")
    private String Type;
}

@Embeddable
public class CompoundKey implements Serializable
{
    @Embedded
    private PartitionKey partitionKey;
    @Column(name = "LABEL")
    private String label;
}

@Embeddable
public class Comment
{
    @Column(name="comment")
    private String comment;
}

@Entity
@Table(name = "MY_ENTITY", schema = "xyz@cassandra_pu")
public class MyEntity
{
    @EmbeddedId
    private CompoundKey primaryKey;

    @ElementCollection
    @Column(name = "COMMENTS")
    private List<Comments> comments;
}

Here is the snippet used for retrieval:-

Query q = entityManager.createQuery("Select e from MyEntity e where e.primaryKey.partitionKey.Id = :Id and e.primaryKey.partitionKey.Type = :Type");
    q2.setParameter("Id", "ID1");
    q2.setParameter("Type", "BOOK");
    List<MyEntity> list=q2.getResultList();

Am getting null pointer exception for the above:-

java.lang.NullPointerException: null
    at         com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.setElementC    ollection(CassandraDataHandlerBase.java:1566) ~[kundera-cassandra-    3.9.1.jar:na]
    at     com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateVia    Thrift(CassandraDataHandlerBase.java:1154) ~[kundera-cassandra-    3.9.1.jar:na]
    at     com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.onColumn(Ca    ssandraDataHandlerBase.java:1054) ~[kundera-cassandra-3.9.1.jar:na]
    at     com.impetus.client.cassandra.datahandler.CassandraDataHandlerBase.populateEnt    ity(CassandraDataHandlerBase.java:653) ~[kundera-cassandra-3.9.1.jar:na]
    ... 15 common frames omitted

Here is my table creation script:-

create TABLE "MY_ENTITY"
(
    "ID" TEXT,
    "TYPE" TEXT,
    "LABEL" TEXT,
    "COMMENTS" list<frozen <"COMMENT">>,
    PRIMARY KEY("ID","TYPE","LABEL")
);

The Comment User Defined Type definition is :-

CREATE TYPE "COMMENT" (
    comment text
);

If I use a simple entity without composite key the query just works fine. Am I missing anything?

UPDATE: When I remove the comments attribute it works fine.


回答1:


This issue has been fixed!

https://github.com/impetus-opensource/Kundera/issues/953

It is available in Kundera 3.10



来源:https://stackoverflow.com/questions/45467495/kundera-cassandra-jpql-with-compound-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!