I dug on this more last night, traced into the debugger etc., and it turned out that you *have* to have a FilterDef along with your Filter. In other words, this worked:
Code:
@Entity
@Name("blogPost")
@FilterDef(name="headOnly")
@Filter(name="headOnly", condition="replicatedChangeset_id is null")
public class BlogPostImpl implements BlogPost, Serializable ...
Leaving out the @FilterDef results in the "No such filter configured" error (which should be "No such FilterDef and Filter configured"). Leaving out the @Filter (but leaving the @FilterDef) results in the enableFilter call apparently working, but no actual filtering happens!
And also, note that I had to change it to "replicatedChangeset_id is null" -- just "replicatedChangeset is null" didn't work. The filter text seems to be just stuck on the end of the where clause -- it's a SQL fragment, not an HQL fragment. This is definitely unexpected and could be a maintenance problem. The more I look at the Filter implementation, the more I have a few questions:
1) Anyone out there really using Filters in production for something?
2) Is there *any* SQL parsing or rewriting done on the Filter condition?
3) Is it possible to have Filters that specify join conditions? On the face of it, it seems like not, unless you play careful games with using only databases that support subselects in WHERE clauses. I want to write a filter that is basically this:
Code:
@FilterDef(name="oldVersion", parameters=("key", "maxIndex")
@Filter(name="oldVersion", condition="replicatedChangesetIndex = (select max(replicatedChangesetIndex) from BlogPostImpl bp2 where bp2.key = key and bp2.replicatedChangesetIndex < :maxIndex)")
Note that part of the where clause is to the "key" field of the "this" object, not to a query parameter. Does this have a hope in hell of working? I guess I'll soon know.
4) What's next for Hibernate? Is there still much active development on extending fringe features like Filters? If I submit a JIRA patch, is it likely to get rolled into a 3.3 (or whatever the next planned version is)? What *is* the next planned Hibernate version?
Cheers!
Rob