title: Hibernate: queries by example and many-to-one relationships
body: <p>Let's say those are my entities:</p>
  
  <p><em>Table1.java</em></p>
  
  <pre><code>@Entity
  public class Table1 {
  
      // Many to one
      private Table2 table2;
  
      // Raw attributes
      // ...
  
  }
  </code></pre>
  
  <p><em>Table2.java</em></p>
  
  <pre><code>@Entity
  public class Table2 {
  
      // Many to one
      private Table3 table3;
  
      // Raw attributes
      // ...
  
  }
  </code></pre>
  
  <p><em>Table3.java</em></p>
  
  <pre><code>@Entity
  public class Table3 {
  
      // Raw attributes
      private String lang; // "fr", "en", "de"...
  
  }
  </code></pre>
  
  <p>I wanna list all the <code>Table1</code> rows that have a <code>table2.table3.lang</code> that equals <code>en</code>. I tried to use a query by example:</p>
  
  <pre><code>Table3 table3Example = new Table3();
  table3Example.setLang("en");
  
  Table2 table2Example = new Table2();
  table2Example.setTable3(table3Example);
  
  Table1 table1Example = new Table1();
  table1Example.setTable2(table2Example);
  
  table1Repository.findByExample(table1Example);
  </code></pre>
  
  <p>The problem is that <code>.findByExample(table1Example)</code> returns all the rows of the database, no matter of the <code>lang</code>, which means that the filter isn't considered at all <code>:(</code></p>
  
  <p>Any help would be appreciated <code>:)</code></p>
  
  <p>PS: no exception is thrown, <code>.findByExample(table1Example)</code> just returns all of the <code>Table1</code> rows.</p>