I have been working on some upgrading which lead to some code using hibernate 3.6.8 instead of hibernate 3.2.7. This caused some problem in the code and after some debugging I found out the problem is in the Hibernate Filter. Here is the class with the filter annotations:
Code:
@Entity
@FilterDefs( {
@FilterDef(name = "asOfFilter", parameters = {@ParamDef(name = "asOfDate", type = "timestamp")}),
@FilterDef(name = "currentFilter", parameters = {})})
@Proxy(lazy = false)
@javax.persistence.Table(
name = "nmeIdt"
)
public class NameIdt {
...
@org.hibernate.annotations.Filters({
@org.hibernate.annotations.Filter(name = "asOfFilter", condition = "fromDate <= :asOfDate AND (currentFlag = 1 OR toDate > :asOfDate)"),
@org.hibernate.annotations.Filter(name = "currentFilter", condition = "currentFlag = 1") })
@javax.persistence.OneToMany(mappedBy = "identity", fetch = javax.persistence.FetchType.EAGER, cascade = javax.persistence.CascadeType.ALL, targetEntity = NameVrs.class)
@Override
protected java.util.Set<Version<?>> getVersions() {
return super.getVersions();
}
...
}
The Filters annotations are correctly added to the Version class, and I am certain that it is enabled. However turning on sql logging it is clear that the filter is not being applied to the query.
After some debugging into the Hibernate I found out the problem is in org.hibernate.persister.entity.AbstractEntityPersister, the FilterHelper this classes uses doesn't seem to pick up the Filters defined in my NameIdt class. This caused the AbstractEntityPersister->isAffectedByEnabledFilters() to return false. However if I put the Filter annotations on the class level instead of the collection property, it works.
To summarise, the FilterHelper does pick up the filters when its defined at the class level but it doesn't when its at the collection property. Is this suppose to happen and if so is there a work around for it? It will also be helpful if there is documentation on what the difference is betweeen when @Filter is attached at class and when its attached to the collection property.