-->
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: How to pass String[] to FilterDef for IN clause?
PostPosted: Fri Apr 03, 2009 11:45 am 
Newbie

Joined: Thu Jun 19, 2008 1:03 pm
Posts: 4
Hibernate version: 3.2.6.GA
Hibernate Annotations version: 3.3.0.GA

I am successfully using a FilterDef and Filter with an integer parameter type. Now I need to filter a collection with an IN clause. I don't know how to define the type on the @ParamDef annotation. If I do the following:

Code:
        @FilterDef(name = "pollutantFilter", parameters = {@ParamDef(name = "codes", type = "string[]")})


I get this error: java.lang.IllegalArgumentException: Undefined filter parameter [codes]

If I make the type just "string", then I get this error:

java.lang.IllegalArgumentException: Incorrect type for parameter [codes]

Here is my filter:

Code:
            @org.hibernate.annotations.Filter(name = "pollutantFilter",
                    condition = "POLLUTANT_CD in {:codes}")


I want to use it like this: getPollutantCodes() returns String[].

Code:
                Filter hfilter = getSession().enableFilter("pollutantFilter");
                hfilter.setParameter("codes", getPollutantCodes());



The SQL is simple. How can I get Hibernate to do it? Thanks.

_________________
Richard Brewster
Senior Associate
Perrin Quarles Associates


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 2:03 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think the filter type needs to be "string" and then you need to use the "setParameterList" method for setting the values. For example:

Code:
hfilter.setParameterList("codes", getPollutantCodes());


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 2:41 pm 
Newbie

Joined: Thu Jun 19, 2008 1:03 pm
Posts: 4
That was exactly what I needed. Thank you!

_________________
Richard Brewster
Senior Associate
Perrin Quarles Associates


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.