SpringBoot How to find records by nested attributes : <p>I have a <strong>User</strong> model which has certain Attributes as depicted below</p>

<pre><code>/**
 * The Class User.
 */
@Entity
@Table(name = "user")
public class User implements UserDetails {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 3961569938206826979L;

    /** The id. */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    /** The first name. */
    private String firstName;

    /** The last name. */
    private String lastName;

    /** The username. */
    @NotNull
    @Size(min = 10, message = "username should have atleast 10 characters")
    private String username;

    /** The password. */
    private String password;

    /** The email. */
    private String email;

    /** The enabled. */
    private boolean enabled;

    /** The last password reset date. */
    private ZonedDateTime lastPasswordResetDate;

    /** The creation date. */
    private ZonedDateTime creationDate;

    /** The phone number. */
    private String phoneNumber;

    private String deviceId;

    /** The authorities. */
    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "user_authority", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "authority_id", referencedColumnName = "id"))
    private List&lt;Authority&gt; authorities;

    /**
     * Gets the id.
     *
     * @return the id
     */
    public long getId() {
        return id;
    }

    /**
     * Sets the id.
     *
     * @param id the new id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Gets the first name.
     *
     * @return the first name
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the first name.
     *
     * @param firstName the new first name
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Gets the last name.
     *
     * @return the last name
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the last name.
     *
     * @param lastName the new last name
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Sets the username.
     *
     * @param username the new username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.security.core.userdetails.UserDetails#getPassword()
     */
    public String getPassword() {
        return password;
    }

    /**
     * Sets the password.
     *
     * @param password the new password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.springframework.security.core.userdetails.UserDetails#getAuthorities()
     */
    @Override
    public Collection&lt;? extends GrantedAuthority&gt; getAuthorities() {
        return authorities;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.security.core.userdetails.UserDetails#getUsername()
     */
    @Override
    public String getUsername() {
        return username;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.springframework.security.core.userdetails.UserDetails#isAccountNonExpired
     * ()
     */
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.springframework.security.core.userdetails.UserDetails#isAccountNonLocked(
     * )
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.security.core.userdetails.UserDetails#
     * isCredentialsNonExpired()
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.springframework.security.core.userdetails.UserDetails#isEnabled()
     */
    @Override
    public boolean isEnabled() {
        return enabled;
    }

    /**
     * Gets the email.
     *
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * Sets the email.
     *
     * @param email the new email
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Gets the last password reset date.
     *
     * @return the last password reset date
     */
    public ZonedDateTime getLastPasswordResetDate() {
        return lastPasswordResetDate;
    }

    /**
     * Sets the last password reset date.
     *
     * @param lastPasswordResetDate the new last password reset date
     */
    public void setLastPasswordResetDate(ZonedDateTime lastPasswordResetDate) {
        this.lastPasswordResetDate = lastPasswordResetDate;
    }

    /**
     * Sets the enabled.
     *
     * @param enabled the new enabled
     */
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    /**
     * Sets the authorities.
     *
     * @param authorities the new authorities
     */
    public void setAuthorities(List&lt;Authority&gt; authorities) {
        this.authorities = authorities;
    }

    /**
     * Gets the creation date.
     *
     * @return the creation date
     */
    public ZonedDateTime getCreationDate() {
        return creationDate;
    }

    /**
     * Sets the creation date.
     *
     * @param creationDate the new creation date
     */
    public void setCreationDate(ZonedDateTime creationDate) {
        this.creationDate = creationDate;
    }

    /**
     * Gets the phone number.
     *
     * @return the phone number
     */
    public String getPhoneNumber() {
        return phoneNumber;
    }

    /**
     * Sets the phone number.
     *
     * @param phoneNumber the new phone number
     */
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        return "User [id=" + id + ", email=" + email + ", firstName=" + firstName + ", lastName=" + lastName
                + ", password=" + password + ", enabled=" + enabled + ", lastPasswordResetDate=" + lastPasswordResetDate
                + ", authorities=" + authorities + "]";
    }

}
</code></pre>

<p>The <strong>Authority</strong> model has following attributes :</p>

<pre><code>/**
 * The Class Authority.
 */
@Entity
public class Authority implements GrantedAuthority
{

   /** The Constant serialVersionUID. */
   private static final long serialVersionUID = -7546748403961204843L;

   /** The id. */
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private long id;

   /** The name. */
   @Enumerated(EnumType.STRING)
   private UserRoleName name;

   /* (non-Javadoc)
    * @see org.springframework.security.core.GrantedAuthority#getAuthority()
    */
   @Override
   public String getAuthority()
   {
      return name.name();
   }

   /**
    * Gets the id.
    *
    * @return the id
    */
   public long getId()
   {
      return id;
   }

   /**
    * Sets the id.
    *
    * @param id the new id
    */
   public void setId( long id )
   {
      this.id = id;
   }

   /**
    * Gets the roles.
    *
    * @return the roles
    */
   @JsonIgnore
   public UserRoleName getRoles()
   {
      return name;
   }

   /**
    * Sets the roles.
    *
    * @param name the new roles
    */
   public void setRoles( UserRoleName name )
   {
      this.name = name;
   }

   /**
    * Sets the name.
    *
    * @param name the new name
    */
   public void setName( UserRoleName name )
   {
      this.name = name;
   }

   /* (non-Javadoc)
    * @see java.lang.Object#toString()
    */
   @Override
   public String toString()
   {
      return "Authority [id=" + id + ", name=" + name + "]";
   }

}
</code></pre>

<p>Now I need to fetch user whose Role is <strong>ROLE_ADMIN</strong>. So do I first need to fetch the object of <strong>Authority</strong> having role as <strong>ROLE_ADMIN</strong> and then call <strong>findOneByAuthority</strong>, or is there something possible with one function?</p>

<p>I am comming from <strong>Django</strong> where fetching a record by nested attributes is very simple?
Someone can help me in this?</p>
