带有Datastax DS-Driver的Kundera抱怨" field"不是UDT

时间:2017-02-17 19:21:26

标签: java cassandra datastax-java-driver kundera

我使用Kundera-Cassandra和Kundera-Cassandra-ds-driver,都使用版本3.7。 H有一个嵌套的对象结构,可以持久存入Cassandra。

对象保持正确,find()返回正确的结果。 但是,在运行简单查询时,它返回" ava.lang.IllegalArgumentException:不是在此UDT"中定义的字段。

    9:11:16.834 [main] INFO  com.impetus.kundera.query.QueryImpl - On getResultList() executing query: Select p from Person p
    09:11:16.834 [main] DEBUG c.i.client.cassandra.query.CassQuery - Populating entities for Cassandra query Select p from Person p.
    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.219 sec <<< FAILURE! - in com.abc.KunderaTest
    test(com.abc.KunderaTest)  Time elapsed: 2.101 sec  <<< ERROR!
    java.lang.IllegalArgumentException: lastName is not a field defined in this UDT
            at com.datastax.driver.core.UDTValue.getAllIndexesOf(UDTValue.java:49)
            at com.datastax.driver.core.AbstractData.getIndexOf(AbstractData.java:66)
            at com.datastax.driver.core.AbstractGettableData.isNull(AbstractGettableData.java:55)
            at com.impetus.kundera.client.cassandra.dsdriver.DSClientUtilities.setBasicValue(DSClientUtilities.java:459)
            at com.impetus.kundera.client.cassandra.dsdriver.DSClientUtilities.setUDTValue(DSClientUtilities.java:431)
            at com.impetus.kundera.client.cassandra.dsdriver.DSClientUtilities.assign(DSClientUtilities.java:393)
            at com.impetus.kundera.client.cassandra.dsdriver.DSClient.iteratorColumns(DSClient.java:909)
            at com.impetus.kundera.client.cassandra.dsdriver.DSClient.populateObjectFromRow(DSClient.java:803)
            at com.impetus.kundera.client.cassandra.dsdriver.DSClient.iterateAndReturn(DSClient.java:792)
            at com.impetus.kundera.client.cassandra.dsdriver.DSClient.executeQuery(DSClient.java:531)
            at com.impetus.client.cassandra.query.CassQuery.populateEntities(CassQuery.java:146)
            at com.impetus.kundera.query.QueryImpl.fetch(QueryImpl.java:1377)
            at com.impetus.kundera.query.QueryImpl.getResultList(QueryImpl.java:200)
            at com.impetus.kundera.query.KunderaTypedQuery.getResultList(KunderaTypedQuery.java:250)

这是我正在运行的查询:

    Query query = em.createQuery("Select p from Person p", Person.class);
    List<Person> persons = query.getResultList();

Person.java

    @Entity
    @Table(name = "PERSON")
    public class Person implements Serializable {

        @Id
        @Column
        public String personId;

        @Embedded
        public Name name;

        @ElementCollection
        public List<Address> addresses = new ArrayList<Address>();

        @Column
        public int age;
    }

Name.java

    @Embeddable
    public class Name implements Serializable {
        @Column
        public String firstName;
        @Column
        public String lastName;
    }

Address.java

    @Embeddable
    public class Address implements Serializable {
        @Column
        public String city;
        @Column
        public String country;
    }

创建表上的Cassandra CQLSH:

    CREATE TYPE mykeyspaces."Address" (
        country text,
        city text
    );

    CREATE TYPE mykeyspaces."Name" (
        "firstName" text,
        "lastName" text
    );

    CREATE TABLE mykeyspaces."PERSON" (
        "personId" text PRIMARY KEY,
        addresses list<frozen<"Address">>,
        age int,
        name frozen<"Name">
    ) 

Thrift的功能很好但DS-Driver不行。 如果我遗漏了任何东西,请告诉我。

谢谢!

1 个答案:

答案 0 :(得分:0)

我调试了代码,这似乎是数据存储驱动程序中的一个错误。

错误:使用case-sensitive名称

获取UDT列

您现在可以使用firstnamelastname之类的解决方法。

以下作品:

@Embeddable
public class Name implements Serializable {
    @Column(
    public String firstname;
    @Column
    public String lastname;
}