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

Revise @PrimaryKey to be an alias for @Column #1476

Closed
spartanhooah opened this issue Feb 7, 2024 · 1 comment
Closed

Revise @PrimaryKey to be an alias for @Column #1476

spartanhooah opened this issue Feb 7, 2024 · 1 comment
Labels
type: enhancement A general enhancement

Comments

@spartanhooah
Copy link

I have a table that has names like resource_key, and the entity POJO is defined like this

@Table("resource_ref")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Uuid implements Serializable {
    private static final long serialVersionUID = 1L;

    @PrimaryKey
    @Column("resource_key")
    private String resourceKey;

    @Column("resource_type")
    private String resourceType;

    @Column("resource_uuid")
    private UUID uuid;

    private boolean uuidAlreadyExists;
}

This causes Cassandra to complain that it can't find the column resourcekey. I have gotten around this by defining a post-processor:

public class CassandraPostProcessor implements BeanPostProcessor {
    public Object postProcessAfterInitialization(@NotNull Object bean, @NotNull String beanName) throws BeansException {
        if (bean instanceof CassandraMappingContext context) {
            context.setNamingStrategy(NamingStrategy.SNAKE_CASE);

            return context;
        }

        return bean;
    }
}

Is there something else I should be doing to make Spring respect the @Column value attribute?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 7, 2024
@mp911de
Copy link
Member

mp911de commented Feb 8, 2024

@PrimaryKey(…) accepts the column name and this annotation is considered only while the @Column annotation is ignored for identifiers. However, it would be a neat idea to accept @Column(…) if both are defined.

@mp911de mp911de changed the title @Column("real_name") is not respected Revise @PrimaryKey to be an alias for @Column Feb 8, 2024
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 8, 2024
@mp911de mp911de added this to the 4.2.3 (2023.1.3) milestone Feb 8, 2024
mp911de added a commit that referenced this issue Feb 8, 2024
…lumn`.

Both annotations are now aliases for `@Column`.

Closes #1476
@mp911de mp911de closed this as completed in d01caa4 Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants