2
votes

I'm trying to map existing Cassandra tables into java classes using spring data cassandra. The table names have uppercase letters, for example "MyTable". However, when I use @Table("MyTable"), spring data cassandra doesn't recognize the table because it treats the name as lowercase.

Is there any way to tell spring data cassandra to not convert the names into lowercase?

Sample code:

import org.springframework.data.cassandra.core.mapping.Table;

@Table("MyTable")
public class MyTable {

}
2

2 Answers

1
votes

In Cassandra's CQL, identifiers like keyspace, table, and column names are case insensitive. If you desire to use mixed case you must quote your names, i.e.:

import org.springframework.data.cassandra.core.mapping.Table;

@Table("\"MyTable\"")
public class MyTable {

}

That being said, I would highly recommend not using mixed case identifiers. While it works, it creates a lot of complexity in having to worry about quoting everything. The convention I see most with Cassandra is to use all lower case use _ as a separator of words, i.e. my_table. You can still use MyTable as your class name to meet java conventions.

1
votes

I was able to solve the problem by adding (forceQuote = true) to @Table annotation.

@Table(value = "MyTable", forceQuote = true)
public class MyTable {

}