开发者

Problem with filtering a collection in hibernate

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜