Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CassandraPersistentPropertyComparator and CassandraPrimaryKeyColumnAnnotationComparator sort properties by column name #1369

Closed
akshaysu opened this issue Apr 5, 2023 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@akshaysu
Copy link

akshaysu commented Apr 5, 2023

I found that when having composite key in the entity, generated DDL differs when @PrimaryKeyColumn.name is used.
spring-data-cassandra version - 4.0.4
java-driver-core - 4.15.0
cassandra server - 4.0.8

Example:

@PrimaryKeyClass
public class PersonKey implements Serializable {
    @PrimaryKeyColumn(name = "firstname", type= PrimaryKeyType.PARTITIONED)
    private String firstName;

    @PrimaryKeyColumn(name="aname", type =  PrimaryKeyType.PARTITIONED)
    private String aName;

    @PrimaryKeyColumn(name="lastname", type = PrimaryKeyType.CLUSTERED)
    private String lastName;

    @PrimaryKeyColumn(name= "bname", type = PrimaryKeyType.CLUSTERED)
    private String bName;
}

Generated DDL is

CREATE TABLE springtest.person (
    aname text,
    firstname text,
    bname text,
    lastname text,
    age text,
    PRIMARY KEY ((aname, firstname), bname, lastname)
) WITH CLUSTERING ORDER BY (bname ASC, lastname ASC)
@PrimaryKeyClass
public class PersonKey implements Serializable {
    @PrimaryKeyColumn(type= PrimaryKeyType.PARTITIONED)
    private String firstName;

    @PrimaryKeyColumn(type =  PrimaryKeyType.PARTITIONED)
    private String aName;

    @PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED)
    private String lastName;

    @PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED)
    private String bName;
}

Generated DDL is

CREATE TABLE springtest.person (
    firstname text,
    aname text,
    lastname text,
    bname text,
    age text,
    PRIMARY KEY ((firstname, aname), lastname, bname)
) WITH CLUSTERING ORDER BY (lastname ASC, bname ASC)

It seems issue is not using class field name as column name while ordering the properties of the primary key class Entity. Please confirm whether this is an issue.

Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 5, 2023
@mp911de mp911de self-assigned this Apr 6, 2023
@mp911de
Copy link
Member

mp911de commented Apr 6, 2023

It is unfortunate to have the name within the column name comparison, but we always considered the column name as comparison argument. This issue is a bug at its core because we should not sort by column name but rather fall back to the field order.

For the time being, please use @PrimaryKeyColumn(ordinal = …) to provide a sort order for your columns.

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 6, 2023
@mp911de mp911de changed the title Generated DDL is different when column name is used in composite primary key CassandraPersistentPropertyComparator and CassandraPrimaryKeyColumnAnnotationComparator sort properties by column name Apr 6, 2023
@mp911de mp911de added this to the 4.2 M1 (2023.1.0) milestone May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants