I have the following example code:
Code:
---- package-info.java -----
@org.hibernate.annotations.FilterDef(name = "filter1", defaultCondition = "5 > myInteger")
package test.hibernate;
-------------
@Entity
public class A {
...
@OneToMany(cascade = CascadeType.ALL)
@Filter(name = "filter1")
public Set<C> getCs() {
...
}
--------------
@Entity
public class C {
...
public int getMyInteger() {
...
}
------ test code --------
...
AnnotationConfiguration config = new AnnotationConfiguration();
config.setProperties(props);
config.addPackage("test.hibernate");
config.addAnnotatedClass(A.class);
config.addAnnotatedClass(C.class);
...
session.enableFilter("filter1");
A a = (A) session.load(A.class, 1);
System.out.println(a.getCs().size());
...
The problem is that fetching of "cs" collection with filter enabled generates wrong SQL:
Code:
select
cs0_.A_ID as A1_1_,
cs0_.cs_ID as cs2_1_,
c1_.ID as ID2_0_,
c1_.myInteger as myInteger2_0_,
c1_.myString as myString2_0_
from
A_C cs0_
left outer join
C c1_
on cs0_.cs_ID=c1_.ID
where
5 > cs0_.myInteger
and cs0_.A_ID=?
That is definitely wrong "cs0_.myInteger ", it should be "c1_.myInteger".
I tried HSQL and MySQL 4.1, Hibernate 3.1 + Annotations 3.1beta8 and Hibernate 3.2CR2 + Annotations 3.2.0CR1. Problem is still there.