-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: why the filter doesn't work on <many-to-one> ?
PostPosted: Thu Sep 14, 2006 5:50 am 
Newbie

Joined: Wed Mar 08, 2006 4:50 am
Posts: 4
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.


Top
 Profile  
 
 Post subject: Re: why the filter doesn't work on <many-to-one> ?
PostPosted: Thu Sep 14, 2006 9:27 pm 
Newbie

Joined: Wed Mar 08, 2006 4:50 am
Posts: 4
no body knows ?!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 3:23 pm 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:44 am
Posts: 27
I have no idea why it doesn't work, we have the same problem.
Perhaps could you add (condtion=visible = '1') to the tag filter, so it works in our project...
Cathy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 15, 2006 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A Hibernate data filter does not change the multiplicity of an association. By definition it therefore does not filter many-to-one, one-to-one, or any load() or get() operation.

What is it supposed to do, return NULL instead of an instance? NULL does not mean FILTERED, it means NULL. You guys are using filters wrong.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.