本文介绍了具有复合密钥的Kundera Cassandra JPQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我将Kundera JPA用于Cassandra.昆德拉版本是:3.8

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

这是我的实体定义:-

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

推荐答案

此问题已解决!

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

它在Kundera 3.10中可用

It is available in Kundera 3.10

这篇关于具有复合密钥的Kundera Cassandra JPQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:27