Transient Field Per Operation

20 views
Skip to first unread message

Julien Sebrien

unread,
Aug 12, 2015, 10:25:26 AM8/12/15
to DataStax Java Driver for Apache Cassandra User Mailing List
Hello,

Is it possible to add attribute to the transient annotation enabling a field to be mapped only for reads (and not for writes)?

Regards,

Julien

Andrew Tolbert

unread,
Aug 12, 2015, 2:34:19 PM8/12/15
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Julien,

The driver doesn't support this using a @Transient annotation or something similar.  If you don't annotate a field on a class, it will not be used.

However, you may be able to achieve this with driver 2.2 and cassandra 2.2.   You can use the 'UNSET' capability introduced in cassandra 2.2 to mark a column as unset.   In the mapper you can pass in Options to operations, including 'saveNullFields' which if set to false will not save columns that are null.  You can also configure the Mapper to never save null values, i.e.:

mapper.setDefaultGetOption(tracing(true), consistencyLevel(QUORUM));
mapper.setDefaultSaveOption(saveNullFields(false));
mapper.setDefaultDeleteOption(consistencyLevel(ONE));

// Given the defaults above, this will use tracing(true), consistencyLevel(ONE)
mapper.get(uuid, consistencyLevel(ONE));

More documentation on this can be found on the Object Mapper feature page under 'Entity Mappers'

Regards,
Andy

Andrew Tolbert

unread,
Aug 12, 2015, 2:41:34 PM8/12/15
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi Julien,

I quickly realized my mistake, got my feature set mixed up :).   This functionality does not use 'UNSET'.   You can use 'saveNullFields' in 2.1.x of the driver as well and it does not require C* 2.2.

Regards,
Thanks

Olivier Michallat

unread,
Aug 12, 2015, 2:49:40 PM8/12/15
to java-dri...@lists.datastax.com
The driver doesn't support this using a @Transient annotation or something similar.  If you don't annotate a field on a class, it will not be used.

To clarify, @Transient will completely ignore the field, there is no way to set it only for reading/writing.
If you don't annotate the field at all, the mapper will try to map it to a column with the same name. 

--

Olivier Michallat

Driver & tools engineer, DataStax


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Julien Sebrien

unread,
Aug 12, 2015, 5:16:20 PM8/12/15
to DataStax Java Driver for Apache Cassandra User Mailing List
Ok, thanks a lot for your answers!

Julien
Reply all
Reply to author
Forward
0 new messages