0
votes

I'm using Kundera-Cassandra with Kundera-Cassandra-ds-driver, both with version 3.7. H have an nested object structure to be persisted into Cassandra.

The object is persisted correctly and find() returns the correct result. However, when running simple query, it returns "ava.lang.IllegalArgumentException: is not a field defined in this 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)

Here's the query I was running:

    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 on created table:

    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">
    ) 

Things work fine with Thrift but not with DS-Driver. Please let me know if I'm missing anything.

Thanks!

1

1 Answers

0
votes

I have debugged the code and this seems to be a bug in datastax driver.

Bug: Fetching UDT columns with case-sensitive names

You can use something like firstname, lastname as a workaround for now.

Following works:

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