我又遇到了HQL的麻烦:(

我想要的SQL是这样的:

select employee.idemployee as id, employee.age as age,
employee.birthday as birthday, employee.firstName as firstName,
employee.gender as gender, employee.lastName as lastName from employee
employee
inner join employee_skillgroups skillgroup1 on
employee.idemployee=skillgroup1.idemployee
inner join employee_skillgroups skillgroup2 on
employee.idemployee=skillgroup.idemployee
where skillgroup1.idskillgroup =  'Sprachen'
and skillgroup.idskillgroup = 'SoftSkills'


但是我只是无法让HQL产生这个...
“ Sprachen”和“ SoftSkills”是从String []中出来的两个字符串,我将方法作为参数。该方法当前如下所示:

public List<Employee> findEmployeeWithTwoSkillGroups(final String[] skillGroups) {
return template.find("from Employee e join e.skillGroups as s where s in ?", Arrays.asList(skillGroups).toString
    ().substring(1, Arrays.asList(skillGroups).toString().length()-1));
}


我将数组“投射”到列表,在其上执行toString()(这样我得到“ [Sprachen,SoftSkills]”),并切断第一个和最后一个字符(所以我得到“ Sprachen,SoftSkills”)。
我猜问题在于,HQL会生成“ [...]。idskillgroup in('Sprachen,SoftSkills')”,就像将两个字符串视为一个字符串一样...
而且我只是无法让它像我想要的那样工作:/

有人可以帮助我,并提示我下一步要做什么吗? :-)

格蕾兹
吉拉拉斯

Simmilar问题:

HQL to get elements that possess all items in a set

最佳答案

这是一个准备好的语句,而不是字符串连接。它像单个字符串一样处理(“ Sprachen,SoftSkills”),因为它是单个字符串。您想在查询中插入一个集合。我不确定如何在hibernateTemplate中执行此操作,但是hibernate本身支持添加集合。参见the hibernate documentation

07-28 00:29