title: QueryDSL re-uses table alias for sub-query
body: <p>I'm having the following simple query:</p>
  
  <pre><code>return new JPAQuery&lt;Job&gt;().from(job)
      .where(job.container.id.eq(cid)
          .and(job.levels.any().in(levels)))
      .fetch();
  </code></pre>
  
  <p><code>cid</code> is of type <code>Long</code>, <code>levels</code> is a list of entities.</p>
  
  <p>QueryDSL generates the following SQL:</p>
  
  <pre><code>SELECT t0.x, t0.y, t0.z
  FROM job t0 
  WHERE (((t0.id = 19) 
      AND EXISTS (
          SELECT 1 
          FROM job t0 
            JOIN (job_level_mapping t3 
             JOIN level t2 ON (t2.id = t3.level_id)) ON (t3.job_id = t0.id),
          level t1 
          WHERE ((t1.id IN (74,77)) AND (t2.id = t1.id)))) 
      AND (t0.job_type = 'SUBMIT'));
  </code></pre>
  
  <p>Note that the table alias <code>t0</code> for table <code>job</code> is the same for the main query and sub-query. This leads to a wrong query result. If I manually rename the alias from the outer <code>FROM</code> from <code>t0</code> to <code>tx</code> and also change <code>(t3.job_id = t0.id)</code> inside the sub-query to <code>(t3.job_id = tx.id)</code>, then the query works as expected.</p>
  
  <p>Is there some way to tell QueryDSL to use different table aliases for the main query and sub-query? Or is there a different way to write this query? </p>
  
  <p>I'm using QueryDSL 4.1.4.</p>
  
  <p>EDIT:
  I'm now using the <code>EntityManager</code> directly with a JPA query and this is
  working:</p>
  
  <pre><code>return getEm().createQuery("SELECT DISTINCT job FROM " +
      "Job job " +
       "WHERE job.container.id = :cid AND job.jobType = :jobType AND job.levels IN :levels", Job.class)
       .setParameter("jobType", JobType.SUBMIT)
       .setParameter("cid", cId)
       .setParameter("levels", levels)
       .getResultList();
  </code></pre>
  
  <pre><code>SELECT DISTINCT t0.x, t0.y, t0.z 
  FROM job t0 
      JOIN (job_level_mapping t2 
      JOIN level t1 ON (t1.id = t2.level_id)) ON (t2.job_id = t0.id) 
  WHERE (((t0.cid = ?) AND (t0.job_type = ?)) AND (t1.id IN (?,?)));
  </code></pre>