Issues/Troubleshooting

Troubleshooting Datastax driver library issue when mapping a Kotlin Boolean field with a Cassandra boolean column type

February 28, 2025

Issue

An exception occurs where you’re being told that a column is missing from your Cassandra (C*) table, but the column name mentioned in the exception message doesn’t match the name of your boolean column.

I found this from running my integration tests with Cassandra were failing because of an exception about a missing column. But is the column actually missing? No, the mapped name seemed to be incorrectly provided by the driver library in the autogenerated mapper class.

Setup

Version
Kotlin1.9.23
Micronaut3.10.4
Datastax Java Driver Mapper Processor4.17.0
Micronaut Cassandra5.1.1

Troubleshooting

Let’s say you have the following data class in Kotlin with a boolean field that starts with “is”:

@Entity
@CqlName("car")
data class Car(
    @field:CqlName("isrunning") var isRunning: Boolean = false
)

And in your Cassandra table, you have a column named similar, “isrunning”.

The Datastax driver mapper seems to not like variables with the word “is” as a prefix. I unfortunately cannot find anything on the internet regarding this so this is just an assumption based on what I’m seeing. I brought this up to a colleague of mine and he had similar thoughts too.

Solution

Change the name of the field to not have the “is” prefix in the Kotlin data class:

@Entity
@CqlName("car")
data class Car(
    @field:CqlName("isrunning") var running: Boolean = false
)

But now it will mess up your serialization/deserialization of the class, so you will need to use the JsonProperty annotation to help with that. See the below for the final solution:

@Entity
@CqlName("car")
data class Car(
    @field:JsonProperty("isrunning") @field:CqlName("isrunning") var running: Boolean = false
)

Learn more!

You may have noticed my use of the @field annotation in the Kotlin data class. This annotation is used when we need to apply the annotation directly to the field rather than the property getter and setter. This is usually required to get field-level annotations working with Kotlin data classes. Read more about it here – https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets!

You Might Also Like

No Comments

Leave a Reply