Java EE,EntitiManager Query,SELECT JOINED实体

时间:2011-05-27 16:50:59

标签: jpa join java-ee entity

这就是我所拥有的(当然是以sintetic形式)

@Entity
public class Event {
    @Id
    private int id;
    private String name;
    private Set<ScheduledEvents> scheduledEvents

}

@Entity
public class ScheduledEvents {
    @Id
    private int id;
    private Date date;

}

如果我想要回顾所有事件......好吧,这很简单:

List<Event> events = em.getResultList("SELECT e FROM Event e");

现在,我想要做的是...将来审核所有已安排的事件(ScheduledEvents)(使用scheduleEvents.date&gt; = TODAY)。我已经制作了这样的东西......当然它不起作用!

List<Event> events = em.getResultList("SELECT e FROM Event e JOIN se WHERE se.date>?1", new Date());

任何帮助?

1 个答案:

答案 0 :(得分:2)

SELECT e FROM Event e JOIN e.scheduledEvents se WHERE se.date > ?1

应该做的伎俩。但是,如果计划在未来的几个日期,您将多次获得相同的活动。使用select distinct e...获取每个活动一次