I have my primary key for a table as Composite key comprised of 3 fields: id, username and email. I want to be able to query a user by either just the username or by just the email without knowing about other keys.
I tried declaring a method in repository but it gives the error No property userKeyUsername found for type User!
Here is my repository interface:
@Repository public interface UserRepo extends CassandraRepository<User, UserKey>{ User findByUserKeyEmail(String email); User findByUserKeyUsername(String username); } I have the following class as a key for my User table.
public class UserKey { @PrimaryKeyColumn(name = "id", ordinal = 0, type = PrimaryKeyType.PARTITIONED) private UUID id; @PrimaryKeyColumn(name = "username", ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String username; @PrimaryKeyColumn(name = "email", ordinal = 0, type = PrimaryKeyType.PARTITIONED) private String email; //equals and hashcode } And this class as my User model:
public class User { @PrimaryKey private UserKey key; @Column("first_name") @CassandraType(type = Name.TEXT) private String firstName; @Column("last_name") @CassandraType(type = Name.TEXT) private String lastName; @Column("password") @CassandraType(type = Name.TEXT) private String password; @Column("roles") @CassandraType(type = Name.LIST, typeArguments = Name.TEXT) private List<Role> roles = new ArrayList<>(); }