-->
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.  [ 3 posts ] 
Author Message
 Post subject: "Where" attribute on collections not actually impl
PostPosted: Thu Oct 13, 2005 3:03 pm 
Newbie

Joined: Mon Jun 13, 2005 6:31 pm
Posts: 9
Section 7.2 of the Hibernate reference manual says that you can add an arbitrary SQL where clause to control what elements of a collection are returned:

Quote:
where (optional) specify an arbitrary SQL WHERE condition to be used when retrieving or removing the collection (useful if the collection should contain only a subset of the available data)


I have a mapping that uses this:

Code:
<set name="children" inverse="true" cascade="all"
    access="field" order-by="sort" where="deleted=0">
    <key column="parent_id" />
    <one-to-many class="ProductCategory" />
</set>


"where" is definitely part of the DTD and is supposed to be valid for a set mapping. And yet when I try this, it appears to have no effect. In my testing it wasn't working and so I started looking at the generated SQL and didn't find the where clause.

Next I added a nonsense condition that doesn't match my table or object structure at all and which should have caused an error (where="foobar=0"). On testing "foobar" doesn't appear in the generated SQL, nor does Hibernate ever throw any errors when this mapping is used.

This behavior happens under the current 3.1 release candidate as well as an older CVS snapshot of 3.1 I had. I can't easily test under 3.0 because my app has 3.1-specific functionality.

Is the documentation incorrect, 3.1 broken, or am I missing some way to turn this functionality on? Thanks.


Top
 Profile  
 
 Post subject: Followup
PostPosted: Fri Oct 14, 2005 10:16 am 
Newbie

Joined: Mon Jun 13, 2005 6:31 pm
Posts: 9
Regarding my previous post, in part I was a victim of caching. Putting in an invalid where clause will cause an error. However the problem remains for me that a syntactically correct where clause has no effect. I must have the syntax wrong.

I have a standard parent-child relationship on a single entity type, Product.

Code:
<class name="Product" table="products">
...
      <set name="children" inverse="true" cascade="all"
         access="field" order-by="sort" where="deleted=0">
         <key column="parent_id" />
         <one-to-many class="Product" />
      </set>
...
<property name="deleted" access="field" type="boolean" />
</class>


I want the children set to be filtered by whether the deleted field is false (0). According to the docs, it seems that the above would do it, but it has no effect. I thought that it might need to be specified whether I am checking deleted on the parent or the child, and further, since it's raw SQL, it might need to have the placeholders for Hibernate aliases and thus would need to be something like:

Code:
   where="{children.deleted}=0


But apparently that isn't legal syntax. Any suggestions?


Top
 Profile  
 
 Post subject: Re: Followup
PostPosted: Fri Oct 14, 2005 10:38 am 
Beginner
Beginner

Joined: Sat Sep 17, 2005 6:50 am
Posts: 23
Hello!

I have the same problem. See my post, maybe it will give you more ideas.

I have also find out, that the documentation does not reflect the current state: for example in <many-to-many> I can use where="", but nothing is said about that in docu.


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