I was wondering if there is any shortcut I missed for making multple or restrictions.
Let's say I have an object.
Code:
class TestObj {
private String testStr=null;
public getTestStr(){
return testStr;
}
public setTestStr(String testStr){
this.testStr=testStr;
}
}
Let's assume I have all my mappings and configuration set up.
At some point I have a List<TestObj> and I want to get all of the TestObj that have any of the values of testStr in my list.
(This is a good test if testStr is unique in your db as you should get back the same List<TestObj> you had in the first place, if the or's are correct.)
I am looking to build a "querry" that looks like
Code:
SELECT * FROM test_objects WHERE (test_str='a' OR test_str='b' OR test_str='c' );
from the List<TestObj>.
Notice there are more than two possibilities and they are all on the same object and data member.
I am looking for an example of how best to do the above without using hard coded SQL.
I have been playing arround with Restrictions.or and I can't seem to wrap my head arround this one.
I tried using multiple Restrictions.or in .add()
like;
.add(
Restrictions.or(Restrictions.eq("testStr","a"),Restrictions.eq("testStr","b"))
)
.add(
Restrictions.or(Restrictions.eq("testStr","c"),Restrictions.eq("testStr","d"))
)
and the SQL output lookes like
Code:
where
(
this_.testStr=?
or this_.testStr=?
)
and (
this_.testStr=?
or this_.testStr=?
)
The above makes sense to me but does not give me any clue as to how to restrict by 3 Criteria or more.
I assume I am missing something simple.
Any help will be greatly apreciated.