0

We have a table where two columns are:

user_assignments      frozen<list<shift_user_assignment>>,
user_offers           frozen<list<shift_user_assignment>>,

and shift_user_assignment is

CREATE TYPE IF NOT EXISTS shift_user_assignment (
 id  timeuuid,
 note varchar,
 breaks frozen<list<shift_break>>)

I have DB entity POJO called shift with these two properties (other properties ignored).

@Column("user_assignments")
private List<UserAssignment> userAssignments;

@Column("user_offers")
private List<UserAssignment> userOffers;

I try to update user_assignments and user_offers using QueryBuilder.

Update update = QueryBuilder.update(ShiftById.TABLE_NAME);
    update.with(QueryBuilder.set("user_assignments", shift.getUserAssignments()))
           .and(QueryBuilder.set("user_offers", shift.getUserOffers()))
          .where(QueryBuilder.eq("company_id", companyId))
            .and(QueryBuilder.eq("id", shift.getId()));
cassandraTemplate.execute(update)

but I receive

org.springframework.cassandra.support.exception.CassandraTypeMismatchException: Value 0 of type class java.util.ArrayList does not correspond to any CQL3 type; nested exception is com.datastax.driver.core.exceptions.InvalidTypeException: Value 0 of type class java.util.ArrayList does not correspond to any CQL3 type
at org.springframework.cassandra.support.CassandraExceptionTranslator.translateExceptionIfPossible(CassandraExceptionTranslator.java:84) ~[spring-cql-1.5.3.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.potentiallyConvertRuntimeException(CqlTemplate.java:946) ~[spring-cql-1.5.3.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.translateExceptionIfPossible(CqlTemplate.java:930) ~[spring-cql-1.5.3.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.translateExceptionIfPossible(CqlTemplate.java:912) ~[spring-cql-1.5.3.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:278) ~[spring-cql-1.5.3.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.doExecute(CqlTemplate.java:559) ~[spring-cql-1.5.3.RELEASE.jar:na]
at org.springframework.cassandra.core.CqlTemplate.execute(CqlTemplate.java:1333) ~[spring-cql-1.5.3.RELEASE.jar:na]

No issues if I store the entity using Spring Data Cassandra. Any clue what/where/how should I map to be able to update these two columns with QueryBuilder? Thank you in advance!

1
  • It's really hard to help if you aren't adding more information to your question. Still Missing is how your Pojo implementation looks like. Which annotations did you use? Furthermore you should update your example in regards to my latest comments. Jan 9, 2018 at 17:28

1 Answer 1

0

You cannot Update Frozen types at all. You can only insert them.

A way to work around this, would be to get the current value first, assign it to a new Arraylist, and do an insert with the same entity but the new list.

See https://docs.datastax.com/en/cql/3.3/cql/cql_reference/collection_type_r.html

Update 1

You should annotate your Pojo field with @FrozenValueotherwise the mapper doesn't know what to do.

See http://docs.datastax.com/en/developer/java-driver/3.2/manual/object_mapper/creating/#mapping-collections

Update 2

You should also annotate your type POJOS with @UDT(name="UserAssignment").

11
  • that's what I am doing - I am setting new arraylists
    – walv
    Jan 8, 2018 at 14:06
  • Yeah but you do QueryBuilder.update. This should be QueryBuilder.insert I think. Jan 8, 2018 at 14:07
  • frozen means that I can't insert/delete new value in the list itself, but complete reinsert/reassign of the list should work. And with QueryBuilder, as you can see, it throws mapping exception.
    – walv
    Jan 8, 2018 at 14:07
  • if I am not mistaken, update is the same insert except it should crash if record is not found by Primary Key (however not 100% sure.)
    – walv
    Jan 8, 2018 at 14:08
  • 1
    See github.com/datastax/java-driver/blob/3.2.x/driver-mapping/src/… and github.com/datastax/java-driver/blob/3.2.x/driver-mapping/src/… both are still there. Also the Error message clearly states that you have a mapping issue there. Jan 9, 2018 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.