title: HQL to retrieve list of distinct entities in many to one relationship
body: <p>In my application users can generate requests for things so I have two entities Request and User mapping to underlying tables of the same name. There is a many to one relationship such that a user can make many requests. My Request entity therefore looks like this</p>
  
  <pre>
  
      @Entity
      @Table(name="request")
      public class Request implements Serializable {
          private int id;
          private User requester;
  
          @Id
          @Column(name="ID", unique=true, nullable=false)
          public int getId() {
              return this.id;
          }
  
          @ManyToOne(fetch=FetchType.EAGER)
          @JoinColumn(name="REQUESTER", nullable=false)
          public User getRequester() {
              return this.requester;
          }
      }
  
  </pre>
  
  <p>I need to get a list of of all users that have made at least one request.</p>
  
  <p>I have tried the following:</p>
  
  <pre>
  
      public List&lt;User&gt; retrieveAllRequesters() {
          return hbSession().createQuery("select requester from Request r left join r.requester as requester").list();
      }
  
  </pre>
  
  <p>but this returns an entity for each request</p>
  
  <p>I tried adding the <strong>distinct</strong> keyword like this:</p>
  
  <pre>
  
         select distinct requester from Request r left join r.requester as requester
  
  </pre>
  
  <p>but that resulted in an HQL syntax error</p>
  
  <p>I tried quite a few other things, changing the <strong>left</strong> join to <strong>inner</strong> and <strong>outer</strong> but without success.</p>
  
  <p>I'd appreciate a suggestion for the HQL to do what I need. Thanks.</p>
  
  <p>Bohemian has suggested that this could be a dialect problem so I have enabled hibernate.show_sql and it is showing the following:</p>
  
  <pre>
  Hibernate: 
      select
          distinct user1_.ID as ID10_,
          user1_.EMAIL_ADDRESS as EMAIL2_10_,
          user1_.EXTERNAL_ID as EXTERNAL3_10_,
          user1_.IS_ADMINISTRATOR as IS4_10_,
          user1_.IS_SUPERVISOR as IS5_10_,
          user1_.IS_TECHNICIAN as IS6_10_,
          user1_.LAST_CHECKED_IN_AT as LAST7_10_,
          user1_.LAST_LOGGED_IN_AT as LAST8_10_,
          user1_.LAST_UPDATED_AT as LAST9_10_,
          user1_.NAME as NAME10_,
          user1_.UI_PREFERENCES as UI11_10_ 
      from
          request request0_ 
      inner join
          [user] user1_ 
              on request0_.REQUESTER=user1_.ID
  2255 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 421, SQLState: S0001
  2255 [main] ERROR org.hibernate.util.JDBCExceptionReporter - The text data type cannot be selected as DISTINCT because it is not comparable.
  </pre>
  
  <p>The database is MS SQL Server.</p>