title: Spring Data use parameters in select clause of @Query
body: <h3>Goal</h3>
  
  <p>I am trying to define a generic query that allows me to list the possible (distinct) values of a property, possibly nested, of an entity. The goal is to have a drop down selection for the end user to choose from when filtering down the list of entities.</p>
  
  <h3>Setup</h3>
  
  <pre><code>@Entity
  public class Customer {
    @Id @GeneratedValue Long id;
    @NotNull String name;
    @Embedded @NotNull Address address;
    ...
  }
  
  @Embeddable
  public class Address {
    String country;
    String city;
    String postalCode;
    String street;
    String number;
    ...
  }
  
  public interface CustomRepository {
    @Query("select distinct ?1 from #{#entityName}")
    List&lt;String&gt; findAllValues(String value);
  
    @Query("select distinct ?1.?2 from #{#entityName} where ?1 IS NOT NULL")
    List&lt;String&gt; findAllSubValues(String path, String value);
  }
  
  public interface RepositoryCustomer extends
      CrudRepository&lt;Customer, Long&gt;,
      JpaSpecificationExecutor&lt;Customer&gt;,
      CustomRepository {}
  </code></pre>
  
  <h3>Usage</h3>
  
  <p>The query could then be used as follows to show a selection box for filtering down the customers list based on their address country:</p>
  
  <pre><code>public class SelectionComponent {
    @Autowired RepositoryCustomer repo;    
    ComboBox&lt;String&gt; select = new ComboBox&lt;String&gt;();
  
    @PostConstruct
    void onPostConstruct() {
      select.setItems(repo.findAllSubValues("address", "country"));
    }
  }
  </code></pre>
  
  <h3>Problem</h3>
  
  <p>Compiling the above setup results in follow exception:</p>
  
  <pre><code>org.hibernate.QueryException: Parameters are only supported in SELECT clauses when used as part of a INSERT INTO DML statement
  </code></pre>
  
  <h3>Question</h3>
  
  <p>It seems this is not supported. Any alternative suggestions?</p>