I am using hibernate. I have a requirement to add a where condition dynamically. I send list of strings.
select * from employee.
Now I need to add where condition as:
select * from employee where name like :somename or name like:othername
Here somename and othername are named parameters. Values are set from list of strings.
In this case the list can contain two strings so that for both named params values can be set.
How can I use names for named params?
Right now I am using a list of strings for both named params and to set their values.
Problem is there are few restrictions to use named params.
Named param should not contain special chars (-,/ and space). Also named param should not be longer than 30 chars.
If my list of strings has any name with above special chars or its length is more than 30 chars then exception is thrown if such a string is used as named param.
How can I use named params for each string in the list?
Have you tried using Criteria API
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html
Well select with bunch of “where” should not be a probelm with criteria API..
just care about the LIKE %
and check this out, and tell me if you need more detail.
http://www.javalobby.org/articles/hibernatequery102/