我有 2 个类处于一对多关系中:
Class Competition{
@OneToMany(fetch=FetchType.EAGER, mappedBy="competition")
public Set<Event> getEvents() {
return events;
}
}
Class Event{
@ManyToOne
@JoinColumn(name="id_competition")
public Competition getCompetition() {
return competition;
}
}
当我运行下面的查询时,我会收到更多的数据。在数据库中,我有一个竞赛条目,我们称之为 c1,以及 3 个事件:e1、e2 和 e3。其中一个事件不符合条件(e1 的 stardate < '2013-09-13')但是当我运行查询时,我得到 3 个事件而不是只有 2 个。我确定数据库中的数据,所以是什么where 子句的问题?
"select com from Competition as com inner join com.events event where event.expectedStartdate > '2013-09-13' "
另外,我必须指定如果我删除满足条件的 2 个事件并保留不满足条件的事件,则查询不返回任何内容(无对象竞争)。
我也尝试了该with
子句,但得到了相同的结果。