所以 - 总的来说,我是 hiberate 和 Java 的新手。我已经看到了几个关于此错误的线程,但似乎没有一个适合我的情况。我有一个简单的 JPQL 查询,如下所示,它应该从函数表/实体返回函数 ID 和名称。此查询保存在我的 FunctionRepository.java 中
@Query("SELECT func.functionId, func.functionName"
+ " FROM Function func")
List<Function> findItAll();
-----below is my FunctionService.java-------
public ArrayNode getAllFunctions() {
ArrayNode json = null;
try {
List<Function> functions = (List<Function>) functionRepository.findItAll();
json = crudEntitiesToJson(functions);
} catch (CorruptDataException cdEx) {
logger.error(cdEx.getMessage());
}
return json;
}
“crudEntitiesToJson”方法如下;
private ArrayNode crudEntitiesToJson(Iterable<Function> entities) throws CorruptDataException {
ArrayNode result = new ArrayNode(JsonNodeFactory.instance);
for (Function entity : entities) {
result.add(FunctiontoJson(entity));
}
return result;
}
所有这一切都是由我的 FunctionController.java 开始的
该项目构建并运行良好,但是当我尝试点击启动该查询的端点时,出现以下错误:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.ge.starfish.entity.Function
我想我很困惑我哪里出错了。
提前致谢。
为。。改变
@Query("SELECT func FROM Function func")
List<Function> findItAll();
检索所有函数而不是具有两个属性的数组。它也可以:
@Query("FROM Function")
List<Function> findItAll();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句