Java – HQL, where in indicates an empty list crash
•
Java
I have an HQL statement like this:
Select cast(ed.employee.employeeID as int) AS emp_id FROM Education AS ed WHERE ed.type.name IN (:typeNames)
But sometimes typenames is empty This can lead to the following:
org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [Select cast(ed.employee.employeeID as int) AS emp_id FROM Education AS ed WHERE ed.type.name IN ()]
What is the solution to accept empty lists?
Solution
One solution I use is to put some virtual values in the list with the input to ensure that it will never be empty Of course, this can only be achieved by selecting virtual values
If your input list is typenamesorig:
List<String> typeNames = new ArrayList<String>(typeNamesOrig); typeNames.add("valueThatDoesNotExistForSure"); query.setParameterList("typeNames",typeNames);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码