inner join querydsl with where clause
<p>Suppose I have this table service_providers that has a self reference via an enterprise_id column.</p>

<pre><code> id            enterprise_id

 102         57
 103         57



  public class ServiceProvider {
       ....
       @ManyToOne
       @JoinColumn(name = "enterprise_id")
       private ServiceProvider enterprise;
 }
</code></pre>

<p>What I am trying to do si having an enterprise_id get all servive_providers. This is pretty easy in SQL:</p>

<pre><code>  select sp1.id
  from service_providers sp1 
  inner join service_providers sp2 on (sp1.enterprise_id=sp2.id) 
  where sp2.id=57;
</code></pre>

<p>But when trying to replicate that via query-dsl I somehow get into problems.</p>

<p>Here is what is looks like :</p>

<pre><code>  QServiceProvider serviceProvider2 = new   QServiceProvider("serviceProvider2");
  QServiceProvider serviceProvider3 = new QServiceProvider("serviceProvider3");



    query.from(serviceProvider2)
            .innerJoin(serviceProvider3)
            .on(serviceProvider2.enterprise.id.eq(serviceProvider3.id))
            .where(serviceProvider3.id.eq(enterpriseId))
            .list(serviceProvider2.id);
</code></pre>

<p>This is what hibernate generates :</p>

<pre><code> select  sp1.id 
 from service_providers sp0 
 cross join service_providers sp1 
 inner join service_providers sp2 on (sp1.enterprise_id=sp2.id) 
 where sp0.id=? and sp2.id=?
</code></pre>

<p>This is a little bit confusing, besides being wrong.</p>

<p>Can anyone tell me what I am doing wrong here?</p>