I’m facing a kind of strange problem and don’t know in which direction to go to solve it 😉
I’m currently developing a web application for storing employees using Hibernate.
Inserting, deleting, searching; everything works just fine.
But!
Every employee has a property represented by a list of Strings.
I want to search for one or for two or more entries in this property (it has to do with skills of the employee;
e.g: I search for “Databases” or for “Databases, Administration”, which would bring up every employee that has “Databases” and “Administration” in his/her skillGroups-property).
If I search for just one skill group, everything works as expected.
But when I try to search for two or more skill groups, Hibernate keeps on throwing a QueryException, although the generated SQL seems to be correct (if I execute it directly in the MySQL-Workbench, I get the expected result).
The exception is the following:
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:231)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101)
org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Following is the SQL I want to generate:
SELECT *
FROM employee.new_view
WHERE idemployee IN (
SELECT idemployee
FROM employee.employee_skillgroups
WHERE idskillgroup = 'Sprachen')
AND idemployee IN (
SELECT idemployee
FROM employee.employee_skillgroups
WHERE idskillgroup = 'Services')
You probably need to use
session.createSQLQuery(sqlString)notsession.createQuery(sqlString)when creating your query.