title: @ManyToOne retrieve objects that contain a partial key using @JoinColumnOrFormula
body: <p>I'm having trouble using @JoinColumnOrFormula to retrieve specific data using a part of a key.
  Let's try to explain the context.</p>
  
  <p>There are two tables in the database that don't have dependency each other.</p>
  
  <p>Here are the definition of those tables:</p>
  
  <pre><code>
  
      @Entity
      @Table(name = "table_A")
      @IdClass(TableAPK.class)
      public class TableA {
  
          @Id
          @Column(name = "tableA_key")
          private String key;
  
          @Id
          @Column(name = "tableA_product")
          private String product;
  
          @Id
          @Column(name = "tableA_territory")
          private String territory;
  
          @Column(name = "tableA_description")
          private String description;
  
          @OneToMany(fetch = FetchType.EAGER, targetEntity = TableB.class)
          private List listTableB;
  
          // getter/setter
      }
  
  </code></pre>
  
  <pre><code>
  
      @IdClass(TableAPK.class)
      public class TableAPK implements Serializable {
  
          private static final long serialVersionUID = -6343683597717600643L;
  
          private String key;
  
          private String product;
  
          private String territory;
  
          // getter/setter
      }
  
  </code></pre>
  
  <pre><code>
  
      @Entity
      @Table(name = "table_B")
      @IdClass(TableBPK.class)
      public class TableB {
  
          @Id
          @Column(name = "tableB_key")
          private String key;
  
          @Id
          @Column(name = "tableB_product")
          private String product;
  
          @Id
          @Column(name = "tableB_region")
          private String region;
  
          @Column(name = "tableB_description")
          private String description;
  
          @ManyToOne(targetEntity = TableA.class)
          @JoinColumnsOrFormulas(value = {
            @JoinColumnOrFormula(column = @JoinColumn(name = "tableB_key", referencedColumnName = "tableA_key", insertable = false, updatable = false, nullable = false)),
            @JoinColumnOrFormula(column = @JoinColumn(name = "tableB_product", referencedColumnName = "tableA_product", insertable = false, updatable = false, nullable = false)),
            @JoinColumnOrFormula(formula = @JoinFormula(value = "????", referencedColumnName = "????"))
          })
          private TableA tableA;
  
          // getter/setter
      }
  
  </code></pre>
  
  <pre><code>
  
      @IdClass(TableBPK.class)
      public class TableBPK implements Serializable {
  
          private static final long serialVersionUID = -6343683597717600643L;
  
          private String key;
  
          private String product;
  
          private String region;
  
          // getter/setter
      }
  
  </code></pre>
  
  <p>As you can see TableAPK and TableBPK the primary keys are not composed by the same attributes.</p>
  
  <pre><code>
  
      List listElements = em.createQuery("FROM TableA WHERE key = :key ORDER BY territory", TableA.class).setParameter("key", key).getResultList();
  
  </code></pre>
  
  <p>This query should returns a list TableA objects according to the key provided. Each TableA has a list of TableB which match key, product and region that is part of the key.</p>
  
  <p>The key is a string that looks like this "territory_region_product_xxxx"</p>
  
  <p>How can I retrieve the list of TableB that will contain 'table_B.tableB_region' in 'table_A.tableA_key'? </p>
  
  <p>For instance table_A.tableA_key has
  "territoryA_regionA_productA_xxxx"
  "territoryA_regionA_productA_xxxx"
  "territoryA_regionB_productA_xxxx"
  "territoryA_regionB_productA_xxxx"</p>
  
  <p>and table_B.tableB_region has
  "regionA"</p>
  
  <p>In this case how can I get the two first row?</p>
  
  <p>How can I implement this using @JoinFormula?</p>
  
  <p>Is @JoinColumnsOrFormulas a good solution in this case?</p>
  
  <p>Any advice is welcome.</p>