我试图在某个日期间隔内获取所有 MainIntervals。但我总是为空。
这是 JPA 实体
@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; }
在 EJB SessionBeans 我有方法:
public List<MainInterval> findMainIntervalsBetween(Date startDate, Date endDate){
List<MainInterval> resultList = em.createNamedQuery(MainInterval.FIND_BETWEEN, MainInterval.class)
.setParameter("startDate", startDate, TemporalType.DATE).setParameter("endDate", endDate, TemporalType.DATE).getResultList();
return resultList;
}
但是当我使用 CDI 从 JSF 调用它时,结果列表始终为空。虽然我有一些 MainIntervals 满足 startDate 和 endDate 之间的条件。
我将非常感谢教程的每个答案或链接。最好的祝福!