We are using 2.1.4. I am using QBC for querying. It works great for a single table and one to many off that table.
I have a few many-to-many relationships off this main table. It is a normal association. Person - linktable - Country table. The person can have many countries and countries can belong to many people.
I have a query form the user can enter Person attributes and QBC handles this (last name, first name, ..). In building this criteria to submit, if the user selects mulitple countries I want to add that in. I do not see how to do that for an association using the criteria.
Say they want to enter in the search form:
firstname= %B%
lastname= %K%
countries= United States, Canada, Mexico
Since I do not think I can do this by QBC I am looking for different ways to handle this. Any suggestion is helpful.
The current alg is:
if (lastname != null) criteria.add(Expression.like("lname", lastname)
if (firstname != null) criteria.add(Expression.like("fname",firstname)
and so on ...
but I wanted to add
if (countries.notempty() )
loop over selected countries
criteria.add(Expression.eq("country.countrylink.countryId", country[i]
end loop
end if
Of course I can not do the last part above b/c Hibernate knows nothign of that link as it is defined like that.
Can I not combine them?
Can I combine it using Expression.sql?
Can I not use QBC?
Should I use HQL or straight SQL?
Thanks
Kevin
|