spring-projects / spring-data-cassandra

Provides support to increase developer productivity in Java when using Apache Cassandra. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-cassandra/
Apache License 2.0
381 stars 311 forks source link

Cannot resolve table name since 3.4.2 #1293

Closed mackatozis closed 2 years ago

mackatozis commented 2 years ago

Issue

We recently upgraded a module of ours to spring-data-cassandra 3.4.2 and our service is not able to identify any of the Cassandra tables when we are doing a query.

For example, when we try to insert a new entry to a table, we get the following exception:

 com.datastax.oss.driver.api.core.servererrors.InvalidQueryException: table SAMPLE does not exist

Full stacktrace: https://gist.github.com/mackatozis/33f4dfae804d25b9f0f819ac575af34e

If we force our module to use spring-data-cassandra 3.4.1 everything works as expected.

Steps to reproduce

I have created a small demo that reproduces the issue:

https://github.com/mackatozis/cassandra-demo

mp911de commented 2 years ago

We changed the naming behavior for user-provided identifiers. If you provide a table name, then we use the exact lettercasing and let Cassandra's driver's CqlIdentifier figure out whether the name must be quoted. It seems that your schema defines a table with the lowercase name sample. CREATE TABLE IF NOT EXISTS TEST_KEYSPACE.SAMPLE is being converted by Cassandra to CREATE TABLE IF NOT EXISTS test_keyspace.sample.

The fix is to use lowercase names in @Table (and any column annotations). The related changes were #1263 and #1281

mackatozis commented 2 years ago

By converting the name to lowercase, it has indeed fixed the issue.

Are there any plans to create a plugin that will scan the whole module and change the annotation values to lowercase? As of now, my company has hundreds of entities across multiple modules and it would be a tedious task to do the conversion.

mp911de commented 2 years ago

Apologies for the inconvenience, we weren't aware that this change has such a wide negative impact. You could post-process entities and tables programmatically and set lowercase CQL identifiers via CassandraPersistentEntity.setTableName(…)/CassandraPersistentEntity.setColumnName(…). That could be an easier approach. Either by post-processing the MappingContext or even by subclassing MappingContext and post-processing each entity/property as it is being created.