代码之家  ›  专栏  ›  技术社区  ›  G__

休眠查询列表中的项目

  •  4
  • G__  · 技术社区  · 15 年前

    有人能给where子句建议正确的语法吗 in 应用于列表?.hbm文件中的以下查询生成一个解析 例外情况:

    <query name="Nutrient.findNutrients1">
        <![CDATA[from Nutrient as nutrient where nutrient.id in elements(?)]]>
    </query>
    

    例外情况如下:

    需要IDENT,找到'?' SessionFactoryImpl.(395)|错误 营养食品1 网址:org.hibernate.hql.ast.QuerySyntaxception查询语法异常: 营养成分营养素.id在里面 元素(?)

    1 回复  |  直到 15 年前
        1
  •  4
  •   Pascal Thivent    15 年前

    elements 部分问题:

    <query name="Nutrient.findNutrients1">
        <![CDATA[from Nutrient as nutrient where nutrient.id in (:ids)]]>
    </query>
    

    List<Long> vals = Arrays.asList(1L, 2L);
    
    Query q = session.getNamedQuery("Nutrient.findNutrients1");
    q.setParameterList("ids", vals);
    List<Nutrient> result = q.list();