-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-one with class level filter trouble
PostPosted: Thu Jun 22, 2006 9:29 pm 
Newbie

Joined: Thu Feb 09, 2006 11:52 am
Posts: 1
Hello, I'm using Hibernate 3.0.5 y i have follow mapping:

<hibernate-mapping>
<class name="A" table="A">
....

<many-to-one
name="foo"
type="B"
column="cod_foo"
/>
....
</class>
</hibernate-mapping>

and

<hibernate-mapping>
<class name="B" table="b">

<filter name="filter"/>
</class>

<filter-def name="filter">
<!CDATA[[
condition
]]>
</filter-def>
</hibernate-mapping>

When i load of the class A with next code and i activate the filter, it don't activate the filter over class B and i got the wrong result.

Session session = factory.getCurrentSession();

Criteria criteria = session.createCriteria(A.class);
session.enableFilter("filter");

criteria.add(Restrictions.idEq(id));

A a = (A) criteria.uniqueResult();
a.getFoo();

I got following sql:

select ....
from B b0_
where b0_.cod_foo = ?

i will expect to got :
select ....
from B b0_
where b0_.cod_foo = ?
and condition


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 11:23 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I believe that class filters apply to get/load, HQL "from RelevantClass" and Criteria on that class: that is, cases where the filtered class is the "top level" search item. If you want to filter the association between a different class and a collection of the relevant class, you need to set up a different filter specifically for the collection.

I don't know if it's intended to be that way, but I haven't read anything that says that it isn't. I have written code that depends on it working like this, so I'm hoping that it is intended to work like this :) I'm guessing that the rationale is that in the case that you're talking about, you'll end up with a "partial" object (each instance of A you load after turning on the filter isn't a complete A, it's missing some items that really should be in the collection), so you have to really, really want that partial object before hibernate will create it for you. It's too likely that, if someone turns on the class filter for B, they won't realize that other classes are going to be affected, and they'll complain when it happens. So the hibernate developers have made it explicit.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.