找不到查询异常的实体 [英] No entity found for query Exception

查看:146
本文介绍了找不到查询异常的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行以下行:

  String queString = "some query string"
  Query q1 = em.createNativeQuery(queString, T03CallsLog.class);
  T03CallsLog newCall;
  newCall = (T03CallsLog) q1.getSingleResult(); //this line cause the exception after         the first time

wierd情况。
如果我只用一个实例执行它,它可以正常工作,但是如果我和多个实例(mdb的)并行执行,那么第一个实例没有任何expcetions执行,其余的都会得到这个错误: p>

wierd situation. if i only execute it with one instance it works fine, but if i do it parallel with more then one instance(mdb's) then the first one is executed without any expcetions, and all the rest get this error:

10:04:50,750 ERROR [log] ECMSDispatcherMdb.onMessage, error: No entity found for query

任何想法可能会导致什么?以及它第一次如何工作,但是对于其他所有的事件呢,它没有?

any idea what could cause it? and how it works the first time, but for all the rest of the isntances it doesnt?

谢谢,

ray。

推荐答案

错误消息通常告诉你,查询没有返回任何结果。所以 getSingleResult()失败。

The error message usually tells you, that the query returned no result. And so getSingleResult() fails.

考虑使用 getResultList()并且如果您期望空的查询结果,则使用 isEmpty()测试结果:

Consider using getResultList() and test the result with isEmpty() if you expect empty query results:

T03CallsLog newCall = null;
List results = q1.getResultList();
if (!results.isEmpty())
   newCall = (T03CallsLog) results.get(0);
else
   // is it a problem? -> log.

这篇关于找不到查询异常的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆