【问题标题】:Hibernate setParameter String休眠 setParameter 字符串
【发布时间】:2015-06-06 17:32:59
【问题描述】:

return em.createQuery(""" 选择 s.description, avg(c.taktTime) 来自 CountEntity c、SkillEntity s、FwmsUserEntity u、SkillTypeEntity t 其中 c.fwmsUser = u.id AND s.description IN (:skillsList)

            ).setParameter("skillsList", skillsListStr).getResultList()

不返回任何值。列表大小为 0,并且没有 SQL 错误。

但如果我这样做了

return em.createQuery(""" 选择 s.description, avg(c.taktTime) 来自 CountEntity c、SkillEntity s、FwmsUserEntity u、SkillTypeEntity t 其中 c.fwmsUser = u.id AND s.description in ('Shelf Count', 'Notion Count', 'Tube Count', '2nd Count')

            ).setParameter("skillsList", skillsListStr).getResultList()

效果很好。

my String SkillsListStr = "Shelf Count, Notion Count, Tube Count, 2nd Count";

如何使用 setParameter 设置“skillsListStr”?

有什么帮助吗?

【问题讨论】:

    标签: hibernate


    【解决方案1】:

    您好,您将“skillsListStr”变量声明为字符串,但它应该是一个列表,因为这是指定为参数的内容。

    试试这样的:

    List<String> skillsListStr = Arrays.toList(new String[]{"Shelf Count", "Notion Count", "Tube Count", "2nd Count"});

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 2021-11-04
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      • 2011-11-25
      • 2013-05-31
      相关资源
      最近更新 更多