title: Joining classes in ORMLite for Android throws SQL exception: could not find a foreign class or vice versa
body: <p>I'm trying to create a join query using QueryBuilder for two different classes, a <code>Product</code> class and a <code>Coupon</code> class, that references a Product attribute, the <code>storeId</code>.</p>
  
  <pre><code>public class Coupon {
  
      @DatabaseField(columnName = TableColumns.PRODUCT, foreign = true, foreignColumnName = Product.TableColumns.STOREID)
      private Product product;
  }
  
  
  public class Product {
  
      @DatabaseField(columnName = TableColumns.ID, generatedId = true)
      private Integer id;
  
      @DatabaseField(columnName = TableColumns.STOREID, index = true, unique = true)
      private Integer storeId;
  }
  </code></pre>
  
  <p>I need to get a Coupon list based on the Product <code>storeId</code>.</p>
  
  <pre><code>public static List&lt;Coupon&gt; getByProduct(Product product) throws SQLException {
      QueryBuilder&lt;Coupon, String&gt; couponBuilder = dao.queryBuilder();
      QueryBuilder&lt;Product, Integer&gt; productBuilder = Product.dao.queryBuilder();     
      productBuilder.where().eq(Product.TableColumns.STOREID, product.getStoreId());
      return couponBuilder.join(productBuilder).query();
  }
  </code></pre>
  
  <p>This query is throwing a SQL Exception:</p>
  
  <pre><code>04-22 11:26:08.058: W/System.err(19479): java.sql.SQLException: Could not find a foreign class com.cde.express.mccopa.model.Coupon field in class com.cde.express.mccopa.model.Product or vice versa
  
  04-22 11:26:08.059: W/System.err(19479):    at com.j256.ormlite.stmt.QueryBuilder.matchJoinedFields(QueryBuilder.java:554)
  
  04-22 11:26:08.059: W/System.err(19479):    at com.j256.ormlite.stmt.QueryBuilder.addJoinInfo(QueryBuilder.java:525)
  
  04-22 11:26:08.059: W/System.err(19479):    at com.j256.ormlite.stmt.QueryBuilder.join(QueryBuilder.java:316)
  </code></pre>
  
  <p>The exception says my classes are not related by a foreign field, but the Coupon class has a foreign Product attribute, annotated properly. I already checked the database, the values in the tables are correct.</p>
  
  <p>How can I fix it?</p>