'No converter found capable of converting

I am developing a application using Spring Boot where i am implementing Authentication and Authorization.This is my Role Entity

@Entity
public class Role extends BaseModel {

    private String name;
    private Set<User> users;
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY)
    public Set<User> getUsers() {
        return users;
    }

    public void setUsers(Set<User> users) {
        this.users = users;
    }
}

Rold id is in BaseModel.I want to fetch all roles from db for which i wrote a method in RoleRepository like this

@Query("select r.id,r.name from Role r")
List<Role> getAllRoles();

But it retuening me this error

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Integer] to type [@org.springframework.data.jpa.repository.Query com.example.demo.model.Role]

Appreciate the help.



Solution 1:[1]

Try changing your method in the Role repository to:

@Query("select r from Role r")
List<Role> getAllRoles();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gere