-->
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.  [ 7 posts ] 
Author Message
 Post subject: When using a filter, "Undefined filter parametet"
PostPosted: Thu Nov 17, 2005 4:42 am 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
This is all with Hibernate 3.1rc2.

I have a mapping like this:

Code:
   

<class name="acme.Customer">
.......
</class>

<class name="acme.Category" dynamic-update="true">
       <id name="number">
          <generator class="increment"/>
       </id>

       <property name="name" length="200" not-null="true"/>

       <property name="description" length="2000"/>

       <many-to-one name="customer" column="user_number" not-null="true"
            foreign-key="thekey" />

         <filter name="customerFilter" condition=":customer = customer"/>
       
     </class>   
     <filter-def name="customerFilter">
        <filter-param name="customer" type="chiralsoftware.biz.Customer"/>
     </filter-def>


Then when I use this filter like this:

Code:
       session.enableFilter("customerFilter").setParameter("customer", customerObject);


I get an exception and it says, "undefined flter parameter".

When I make up a simple filter that uses a string type and I apply it to a property in the class, all is well, but here I'm filtering on an object type (acme.Customer) and customer is a many-to-one mapping, not a property. How should I handle this?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 4:44 am 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
(By the way, to make something more clear: In my setup, customers have multiple categories. Customers store stuff in their accounts and can put it in categories. I'm making this note because we usually think of customers as being in categories, rather than customers having categories.)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 5:04 pm 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
I found out more about what's going on. From a comment in this discussion: http://www.theserverside.com/news/threa ... d_id=28041 it looks like filters cannot be applied in a many-to-one mapping, which is what I am using.

Is there a solution to this? Surely there is some way to apply a filter so that only objects owned by a given Customer can be viewed?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 5:15 pm 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
Problem solved!

What I need to do is this:

Within my class section of the mapping file:

Code:
       <many-to-one name="customer" column="user_number" not-null="true"
            foreign-key="forkey" />

         <filter name="customerFilter" condition=":customerId = user_number"/>


And then my filter code is:

Code:
     <filter-def name="customerFilter">
        <filter-param name="customerId" type="int"/>
     </filter-def>


In some ways it is less elegant because I'm manually having to use the ID number of customer objects, but it is very workable and does exactly what I want. So I guess that is the solution to using filters in cases where the filtering is aon a many-to-one, instead of on a property. At least it's clear how it's working.

Now I have things set up so that a customer logs in and there is a servlet filter that secures his access to the site, and that servlet filter creates the Hibernate session and the session is also filtered so that a customer can only see his stuff.

This is awesome and the sanest most secure way to develop a web app.

Constrasting this to PHP where there are no filters (either at the DB layer or the web page layer) and there are SQL injection attacks all over the place.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 5:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Nope. Filters are not allowed to change the multiplicity of an association.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 5:57 pm 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
steve wrote:
Nope. Filters are not allowed to change the multiplicity of an association.


I don't understand what you mean by this. By putting a fitler, I'm not changing the multiplicity; I'm only narrowing the objects that could be reached by the association. Does my solution above make sense for this? Is it the right way to do it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I was refering to your question about "can I filter a many-to-one".

The answer is no.

Say you have : Order *-1 Customer.
Further say we did allow a filter to be applied to this association.

Now when you load a particular Order, its customer is null. So when this goes to get saved, what do you think is going to happen?


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