title: How to join on foreign key in querydsl
body: <p>I am new to querydsl and I'm trying to use querydsl in pure java (no hibernate, JPA or anything).</p>
  
  <p>We have a database where the tables are linked through <strong>minimum 3 columns</strong> 
  I followed the doc <a href="http://blog.mysema.com/2011/01/querying-in-sql-with-querydsl.html" rel="nofollow">here</a> and ended up with my schema duly created.</p>
  
  <p>Here are my pseudo tables :</p>
  
  <p><strong>Item</strong></p>
  
  <ul>
  <li>Corporation (pk) <em>mmcono</em></li>
  <li>Item number (pk) <em>mmitno</em></li>
  <li>Environnement (pk) <em>mmenv</em></li>
  <li>Item description <em>mmitds</em></li>
  </ul>
  
  <p><strong>Item_warehouse</strong></p>
  
  <ul>
  <li>Corporation (fk for Item) <em>mbcono</em></li>
  <li>Item number (fk for Item) <em>mbitno</em></li>
  <li>Environnement (fk for Item) <em>mbenv</em></li>
  <li>Warehouse number <em>mbwhlo</em></li>
  <li>Other properties (not important)</li>
  </ul>
  
  <p>Inside the Item_wharehouse class, I manually added the foreignKey (because it's not defined in the actual db schema)</p>
  
  <pre><code> public final com.querydsl.sql.ForeignKey&lt;QItemWharehouse &gt; _ItemWharehouseFk = createInvForeignKey(Arrays.asList(mbitno, mbcono, mbenv), Arrays.asList("mmitno", "mmcono", "mbenv"));
  </code></pre>
  
  <p>I'm working on the following code in my main class:</p>
  
  <pre><code>    SQLTemplates templates = SQLServer2012Templates.builder().printSchema().build();
      Configuration configuration = new Configuration(templates);
  
      QItem mm = new QItem ("mm");
      QItemWarehouse mb = new QItemWarehouse("mb");
  
      JtdsDataSource ds = getDataSource();
      SQLQueryFactory queryFactory = new SQLQueryFactory(configuration, ds);
      String toto = queryFactory.select(mm.mmitno, mm.mmitds)
              .from(mm)
              .join(  ???????????? )
              .where(mb.mbwhlo.eq("122"))
              .fetch()
  </code></pre>
  
  <p>As per doc <a href="http://www.querydsl.com/static/querydsl/2.1.2/apidocs/com/mysema/query/sql/class-use/ForeignKey.html" rel="nofollow">here</a> I should be able to do something like this : <code>AbstractSQLQuery.innerJoin(ForeignKey&lt;E&gt; key, RelationalPath&lt;E&gt; entity)</code></p>
  
  <p>What I want in the end is to <strong>allow joining table without having to specify manually all the columns required for the join condition</strong>.
  As stated before, my model starts with minimum 3 columns in the pk, and it's not uncommon to have 6 or 7 cols in the on clause! It's a lot of typing and very error prone, because you can easily miss one and get duplicate results.</p>
  
  <p>I would like something like <code>.join(mb._ItemWharehouseFk, ???)</code> and let querydsl handle little details like generating the on clause for me. </p>
  
  <p>My trouble is that I can't find the second parameter of type <code>RelationalPath&lt;E&gt; entity</code> for the join method.</p>
  
  <p>I am doing something wrong ? What do I miss ? Is it even possible to accomplish what I want ?</p>