Java HQL未在多个值的“中”工作

Java HQL未在多个值的“中”工作,java,hibernate,Java,Hibernate,我有冬眠,就像这样 String queryString = "from MFunction as mFunction where mFunction.functionKey in " + "((select mRole.enterprise from MRole as mRole where mRole.roleKey=:role), " + "(select mRole2.project from MRole as mRole2 wher

我有冬眠,就像这样

String queryString = "from MFunction as mFunction where mFunction.functionKey in " 
            + "((select mRole.enterprise  from MRole as mRole where mRole.roleKey=:role), " 
            + "(select mRole2.project from MRole as mRole2 where mRole2.roleKey=:role ), " 
            + "(select mRole3.technology  from MRole  as mRole3 where mRole3.roleKey=:role ))";
但是hibernate查询只接受第一个值

Hibernate: select mfunction0_.FunctionKey as Function1_73_, mfunction0_.`Add` as Add2_73_, mfunction0_.`Audit` as Audit3_73_, mfunction0_.ClientKey as ClientKey73_, mfunction0_.CreatedBy as CreatedBy73_, mfunction0_.CreatedTs as CreatedTs73_, mfunction0_.`Delete` as Delete7_73_, mfunction0_.`Edit` as Edit8_73_, mfunction0_.`Financial` as Financial9_73_, mfunction0_.FunctionName as Functio10_73_, mfunction0_.`General` as General11_73_, mfunction0_.Level as Level73_, mfunction0_.LevelKey as LevelKey73_, mfunction0_.LogicalDeleteTms as Logical14_73_, mfunction0_.UpdatedBy as UpdatedBy73_, mfunction0_.UpdatedTs as UpdatedTs73_, mfunction0_.`View` as View17_73_ from appanalytixdb.M_Function mfunction0_ where mfunction0_.FunctionKey in (select mrole1_.Enterprise from appanalytixdb.M_Role mrole1_ where mrole1_.RoleKey=?)

Hibernate版本:4.1.8.Final

您的问题是创建了一个列表列表,并且应该创建一个功能键列表

我只看到两种选择:

将一个“in”语句更改为3个与或相关的语句。 String queryString=从MFunction作为MFunction,其中MFunction.functionKey=从mRole作为mRole选择mRole.enterprise作为mRole其中mRole.roleKey=:role或MFunction.functionKey=从mRole选择mRole2.project作为mRole2,其中mRole2.roleKey=:role或MFunction.functionKey in选择mRole3.technology作为mRole3,其中mRole3.roleKey=:角色

最好的解决方案是预先选择所有项目、技术和企业,并将它们结合在一起以避免重复。但根据这篇文章,hibernate还不支持union。 如果表中没有那么多条目,我将创建一个视图,并对其使用我的查询。在这种情况下,视图可以非常便宜且易于使用。
逗号在引号中。下面的查询将起作用。字符串queryString=从MFunction作为MFunction,其中MFunction.functionKey in+从mRole作为mRole选择mRole.enterprise作为mRole,其中mRole.roleKey=:role,+从mRole选择mRole2.project作为mRole2,其中mRole2.roleKey=:role,+从mRole选择mRole3.technology作为mRole3,其中mRoleKey=:role;