我有以下数据结构:
@Entity
@FilterDef(name="usageHistoryFilter", parameters=@ParamDef( name="updateDate", type="date" ))
@Table(name = "Services")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Service extends DBEntity {
private Set<UsageHistory> usageHistorySet;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "ServiceUsageHistory", joinColumns = @JoinColumn(name = "service_id"), inverseJoinColumns = @JoinColumn(name = "usageHistory_id"))
@Filter(name = "usageHistoryFilter", condition="NEEDED_CONDITION")
public Set<UsageHistory> getUsageHistorySet() {
return usageHistorySet;
}
...
}
@Entity
@Table(name = "UsageHistorys")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class UsageHistory extends DBEntity {
private Date lastUpdateDate;
private AgentDetails agentDetails;
@Column(name = "updateDate")
public Date getLastUpdateDate() {
return lastUpdateDate;
}
@ManyToOne
public AgentDetails getAgentDetails() {
return agentDetails;
}
...
}
@Entity
@Table(name = "AgentDetails")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AgentDetails extends DBEntity {
private boolean local;
@Column(name = "local")
public boolean isLocal() {
return local;
}
}
我试图实现一个查询,它将检索在给定日期之后更新的所有服务,这很容易做到。下一部分:在检索到的服务中设置的usageHistory应该只包含在给定日期之后更新的usageHistory对象,并且它们的agentsDetails对象具有值为'true'的属性'local'。
谷歌搜索了一段时间后,我发现它应该可以使用过滤器。这就是我的问题,我试图自己编写过滤条件但我缺乏知识太大了。我不知道是否有可能创造条件,考虑到我的所有要求。
你能帮我解决这个问题还是指出其他方法来实现它?
我将提到数据库将包含数千个服务,每个服务都有数百万个usageHistory对象。