title: JPQL BETWEEN Date Interval
body: <p>I tried to get all MainIntervals in a certain date interval. But I get always null. </p>
  
  <p>Here is the JPA Entity</p>
  
  <pre><code>@Table(name="MAIN_INTERVAL")
   @NamedQueries({
   @NamedQuery(name = MainInterval.FIND_ALL, query = " select m from MainInterval m"),
   @NamedQuery(name = MainInterval.FIND_BETWEEN, 
      query = "select m from MainInterval m where m.mainIntervalStart 
      BETWEEN :startDate AND :endDate 
      AND m.mainIntervalEnd BETWEEN :startDate AND :endDate"
     )  }) 
  
  
  public class MainInterval implements Serializable {
  
  public static final String FIND_ALL = "MainInterval.findAll";
   public static final String FIND_BETWEEN = "MainInterval.findBetween";
  
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name="MAIN_INTERVAL_ID")
  private Long id;
  
  @Column(name="MAIN_INTERVAL_START")
  @Temporal(javax.persistence.TemporalType.DATE)
  private Date mainIntervalStart;
  
  @Column(name="MAIN_INTERVAL_END")
  @Temporal(javax.persistence.TemporalType.DATE)
  private Date mainIntervalEnd; }
  </code></pre>
  
  <p>And in the EJB SessionBeans I have the method:</p>
  
  <pre><code>public List&lt;MainInterval&gt; findMainIntervalsBetween(Date startDate, Date endDate){
        List&lt;MainInterval&gt; resultList = em.createNamedQuery(MainInterval.FIND_BETWEEN, MainInterval.class)
                .setParameter("startDate", startDate, TemporalType.DATE).setParameter("endDate", endDate, TemporalType.DATE).getResultList();
        return resultList;
  }
  </code></pre>
  
  <p>But when I call it from JSF with CDI the resultList is always null. Although I have some MainIntervals that meet the conditions between startDate and endDate. </p>
  
  <p>I would be very grateful to every answer or links for tutorial. 
  Best regards! </p>