title: Hibernate: How to get a field from a join table using @SecondaryTable with predicate
body: <p>I have 3 tables, but I'm only interested in</p>
  
  <ul>
  <li>table A </li>
  <li>the 'amount' field from A_Cat (this is the join table between "A" and "Category") for a well defined value of cat_Id. This predicate makes the relation a OneToOne instead of a OneToMany.</li>
  </ul>
  
  <p>This is the simplified structure:</p>
  
  <pre><code>CREATE TABLE A
  (
      a_id INT AUTO_INCREMENT PRIMARY KEY,
      title VARCHAR(50) NOT NULL
  );
  
  CREATE TABLE Category
  (
      cat_id INT AUTO_INCREMENT PRIMARY KEY,
      title VARCHAR(50) NOT NULL
  );
  
  CREATE TABLE A_Category
  (
      a_id INT PRIMARY KEY,
      cat_id INT PRIMARY KEY,
      amount INTEGER NOT NULL
  );
  </code></pre>
  
  <p>Java code:</p>
  
  <pre><code>@Entity
  @Table(name = "A")
  @SecondaryTable(name = "A_Category", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "a_id")}))
  public class ModelA {
  
      @Id
      @Column(name = "a_id")
      private Long id;
  
      @Column(name = "amount", table = "A_Category")
      private Integer amount;
  }
  </code></pre>
  
  <p>This generates a join in Hibernate between "A" and "A_Category" for all the possible values.</p>
  
  <p>So, here's my question, how to add a predicate to the SecondaryTable (eg: cat_id = 1).</p>
  
  <p>Can it be done with an annotation? I tried it with @WhereJoinTable but no luck.</p>
  
  <p>PS: I can obtain what I want if I use  @Formula, but if I want more fields from <code>A_Category</code> then the generated sql is not that performant and like to avoid writing sql in my POJO.</p>