-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate filters and combination of parameters with OR
PostPosted: Fri Apr 21, 2006 3:02 am 
Beginner
Beginner

Joined: Wed Apr 05, 2006 5:01 am
Posts: 20
Hibernate version: 3.1.3

Hi,

i have a question regarding the usage of filters.
I have one or more parameters that i want to use in a
hibernate filter. I want these filters to be combined
and have the resulting SQl look like: WHERE param1 = x OR param2 = y ...
Is it possible and how can i do it?

thx for any help!


Top
 Profile  
 
 Post subject: Re: Hibernate filters and combination of parameters with OR
PostPosted: Fri Apr 21, 2006 3:30 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
lasse_stromberg wrote:
Hibernate version: 3.1.3

Hi,

i have a question regarding the usage of filters.
I have one or more parameters that i want to use in a
hibernate filter. I want these filters to be combined
and have the resulting SQl look like: WHERE param1 = x OR param2 = y ...
Is it possible and how can i do it?

thx for any help!


simply add all of them within your class definition:
<class>
<filter name="f1" condition="..." />
<filter name="f2" condition="..." />

_________________
Please don't forget to give credit, if my posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 5:19 am 
Beginner
Beginner

Joined: Wed Apr 05, 2006 5:01 am
Posts: 20
No that's not working!

If i use two filters for example:

Code:
<class>
     ...

    <filter name="filter1" condition=":filterParam = id"/>
    <filter name="filter2" condition=":filterParam = id"/>

</class>     
   
    <filter-def name="filter1">
      <filter-param name="filterParam" type="int"/>
    </filter-def>
    <filter-def name="filter2">
   <filter-param name="filterParam" type="int"/>
    </filter-def>


and enable both within my application code:

Code:
session.enableFilter("filter1").setParameter("filterParam", 1);
session.enableFilter("filter2").setParameter("filterParam", 2);


The generated SQL Where conditions are chained using AND.
But i need OR!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 9:19 am 
Beginner
Beginner

Joined: Wed Apr 05, 2006 5:01 am
Posts: 20
Ok problem solved. I use parameter list and a WHERE IN clause
is generated. According to this thread: http://forum.hibernate.org/viewtopic.php?t=934226&highlight=filterparam


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