Search code examples
jpaormcassandrajpqlkundera

Kundera Cassandra JPQL with Compound Key


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.


Solution

  • This issue has been fixed!

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

    It is available in Kundera 3.10