CFQUERYPARAM 使用 HQL 引发“类型不兼容”错误

问题描述

我的简单查询

<CFQUERY name="thisRecipePreps" dbtype="hql">
    FROM recipeItems r
    WHERE r.recipe = <cfqueryparam value="#thisrecipeid#">
    AND r.otherRecipe_id <> <cfqueryparam value="0">
</CFQUERY>

我的对象 recipeItems 与 'recipe' 具有“多对一”关系,它将返回一个数组(我相信)。我想通过 recipe_id 过滤结果,当我没有 CFQUERYParaM 标签时这有效,但像这样它会抛出错误

Error casting an object of type java.lang.Integer to an incompatible type. This usually indicates a programming error in Java,although it Could also mean you have tried to use a foreign object in a different way than it was designed.

我相信错误意味着“thisrecipeid”变量的类型是“integer”,但“r.recipe”不是。

我想(并且需要)使用 CFQUERYParaM,但我似乎不能。

感谢您的任何见解

注意:我从网站和成员那里得到建议,认为这与另一个据称已解决的问题 (https://stackoverflow.com/a/4185205/4575762) 是同一个问题。然而,问题是通过删除两个实体之间的关系来解决的,这完全违背了使用 ORM/Hibernate 的初衷。通过破坏其他东西来解决问题并不能解决问题。此外,该问题的错误显示了“空指针”问题,此错误是不兼容的类型问题。

解决方法

空格会导致 HQL dbtype https://blog.adamcameron.me/2013/03/whitespace-in-hql-causes-exceptions.html

出现问题