在休眠中过滤集合的问题
我有以下数据结构:
@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;
}
}
我试图实现一个查询,该查询将检索给定日期之后更新的所有服务,这很容易做到。下一部分:检索到的服务中设置的 useHistory 应仅包含在给定日期之后更新的 useHistory 对象,并且它们的agentDetails 对象具有属性“local”,值为“true”。
经过谷歌搜索一段时间后,我发现使用过滤器应该是可行的。我的问题来了,我尝试自己编写过滤条件,但我的知识太缺乏了。我不知道是否有可能创造条件来考虑我的所有要求。
你能帮我解决这个问题或者指出其他方法来实现它吗?
我要提到的是,数据库将包含数千个服务,每个服务都有数百万个 useHistory 对象。
I have a following data structures:
@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;
}
}
I was trying to implement a query that will retrieve all services updated after given date and that is a pretty easy to do. The next part: usageHistory set in retrieved services should contain only usageHistory objects that were updated after given date and their agentsDetails objects have property 'local' with value 'true'.
After googling a while I have found that it should be doable using filters. And here comes my problem, I've tried to write filter condition on my own but my lack of knowledge is too big. I dont know if it is even possible to create condition that will take into consideration all my requirements.
Can you help me with that or point other way to achieve it?
I will mention that database will contain thousands of services each with millions of usageHistory objects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论