我的简单查询:
<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”变量是“整数”类型,但“r.recipe”不是。
我想(并且需要)使用 CFQUERYPARAM,但我似乎不能。
感谢您的任何见解
注意:我从网站和成员那里得到建议,这与另一个本应解决的问题 ( https://stackoverflow.com/a/4185205/4575762 ) 相同。但是,通过删除两个实体之间的关系解决了这个问题,这完全违背了使用 ORM/Hibernate 的初衷。通过破坏其他东西来解决问题并不能解决问题。此外,该问题的错误显示“NULL 指针”问题,此错误是类型不兼容的问题。