-->
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: Setting parameters for dynamic filters
PostPosted: Fri May 27, 2005 6:17 pm 
Beginner
Beginner

Joined: Fri Sep 24, 2004 7:15 am
Posts: 40
Finally, I am giving a try to the new feature of dynamic filters in Hibernate3.

But I have realized that when setting the parameters for the filter, the fact that a filter will not be used is done by simply not setting its parameter. For example:

<filter-def name="filterName">
<filter-param name="likeName" type="string" />
</filter-def>
<filter-def name="filterSurname">
<filter-param name="likeSurname" type="string" />
</filter-def>


And then in code:

session.enableFilter("filterName").setParameter("likeName", "%John%");
session.enableFilter("filterSurname").setParameter("likeSurname", "%Doe%");

So if I don't have a value for, imagine, surname, then I just have to omit the:

session.enableFilter("filterSurname").setParameter("likeSurname", "%Doe%");

But this will lead to having a bunch of if statements asking for the possible values of the parameters, won't it?:

if (IHaveValueForName)
session.enableFilter("filterName").setParameter("likeName", "%John%");
if (IHaveValueForSurname)
session.enableFilter("filterSurname").setParameter("likeSurname", "%Doe%");


Wouldn't it be easier just to set the parameter always, so if it is null then Hibernate just ignores it? For example:

session.enableFilter("filterName").setParameter("likeName", "%John%");
session.enableFilter("filterSurname").setParameter("likeSurname", null);

Because this doesn't work :-(, as Hibernate throws the following exception:

java.lang.IllegalArgumentException: Filter [filterSurname] defined parameter [likeSurname] whose value was not set


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 31, 2005 6:02 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Maybe you should create many filters with each a single attribute and enable it only when the parameter is provided.

_________________
Vincent Giguère
J2EE Developer


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.