Hibernate version : 3.0
why the filter doesn't work on <many-to-one> ?
All the tables in my database have a visibility flag so that queries will only retrieve objects that are not hidden. I'm successfully using Hibernate Filters at class level and collection level
My problem is that I can't see any way to apply the same filter to a nested object that is declared by a many-to-one element in the mapping file.
Code:
<hibernate-mapping>
<class name="User" table="USER">
....
<many-to-one name="group"
type="group"
column="GROUP_ID" />
....
<filter name="visiblefilter" />
</class>
<class name="Group" table="GROUP">
....
<filter name="visiblefilter" />
</class>
<filter-def name="visiblefilter">
visible = '1'
</filter-def>
</hibernate-mapping>
Code:
Session s = sessionFactory.openSession();
String stmt = "from User u where u.id= '1116'";
s.enableFilter("visiblefilter");
List list = s.createQuery(stmt).list();
User user = (User)list0.get(0);
Group group = user.getGroup(); // <-------- here !
......
the filter doesn't work on group.
the sql is
select ....
from Gourp g_
where g_id = ?
but not
select ....
from Gourp g_
where g_id = ? and
visible = '1'
Any help is greatly appreciated.