Is there opportunity to filter query results by complex custom criteria that appears to be only a java function? I would like this criteria functions take a part between entity creation and placing it into result collection.
For instance, I have following entity and query
@Entity
@NamedQueries{
@NamedQuery(name="myquery",query="...")
}
class MyEntity{
@Id
public long id;
@Column(name="NAME")
public String name;
@Column(name="description")
public String description;
}
I can execute myquery and specify paging parameters to get result set with fixed size. But I want to make some additional complex filtering, that can not be expressed by query. If I make some post query processing function and use it to filter query results I would break paging invariant, page size. It would not be nice and convenience.
There’s no simple way to do that. The
setFirstResult()andsetMaxResults()methods are applied on the generated SQL query. In MySQL, for example,LIMIT (10, 10)is added to the where clause of the query). So if you filter the results after the query has been executed, you’ll always get a smaller number of results.