title: Hibernate @Where Q
body: <p>I want to map <code>Train.fares</code> to the Fares class, but only the fares currently active (within effective / expiry date window). In my <code>@Where</code> annotation in Fare, how can I specify that <code>effDate</code> and <code>expDate</code> refer to <code>Fare.effDate</code> and <code>Fare.expDate</code>?</p>
  
  <pre><code>@Entity
  @Table(name = "TRAIN")
  @Configurable
  public class Train {
  
      @Id
      private String id;
  
      @Column
      private Date ddate;
  
      @Column
      private String company;
  
      @Column (name = "NBR")
      private String trainNbr;
  
      @OneToMany(mappedBy = "flight", fetch = FetchType.LAZY)
      @Id
      private List&lt;Fare&gt; Fares;
  
      ...setters &amp; getters
  }
  
  
  @Entity
  @Table(name = "FARE")    
  public class Fare {
  
      @Id
      private Long id;
  
      @Column 
      private String company;
  
      @Column (name = "NBR")
      private string trainNbr;
  
      @Column
      private Date effDate;
  
      @Column 
      private Date expDate;
  
      @ManyToOne
      @JoinColumns({
          @JoinColumn(name = "COMP", referencedColumnName = "COMP", insertable = false, updatable = false),
          @JoinColumn(name = "NBR", referencedColumnName = "NBR", insertable = false, updatable = false)
      })
      @Where(clause = "SELECT t from TRAIN as t where t.ddate &gt;= effDate AND t.ddate &lt;= expDate")
      private Train train;
  
      ...setters &amp; getters
  }
  </code></pre>