1
votes

Kotlin + Spring Boot Cassandra App is ignoring @Column("column_name") annotations. The below annotation

@Column("order_details")
val orderDetails: String

Is being mapped to orderdetails instead of order_details. As the column orderdetails doesn't exist in the table, it causes a run time error.

Why doesn't spring data Cassandra's @Column map to snake case by default? Even after the value is being passed to @Column mapping, why is it being ignored? Is there any other property that needs to be set in the app properties so that spring data Cassandra uses snake case for physical mapping?

@Table("order_by_customer")
data class CustomerOrder(
    @PrimaryKeyColumn(name = "customer_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
    val customerId: UUID,
    @Column("order_details")
    val orderDetails: String,
    @Column("ordered_at")
    val orderedAt: LocalDate
)

Generated insert query INSERT INTO order_by_customer (customer_id,orderdetails,orderedat)

While annotation for PK work the ones for Column are being ignored

1

1 Answers

0
votes

Per the resolution provided by spring-data-cassandra team. Data class need to be coded as shown below

@Table("order_by_customer") data class CustomerOrder( @PrimaryKeyColumn(name = "customer_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED) val customerId: UUID, @field:Column("order_details") val orderDetails: String, @field:Column("ordered_at") val orderedAt: LocalDate )

https://github.com/spring-projects/spring-data-cassandra/issues/1146

https://kotlinlang.org/docs/annotations.html#annotation-use-site-targets