Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No entity found for query Exception

Tags:

java

jpa

jboss

ejb

I am executing the following lines:

  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 

weird 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 exceptions, 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 instances it doesn't?

thanks,

ray.

like image 403
rayman Avatar asked Jan 31 '11 08:01

rayman


2 Answers

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

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. 
like image 178
Andreas Dolk Avatar answered Sep 22 '22 04:09

Andreas Dolk


If a query returns no result, a NoResultException is thrown by getSingleResult(). Are you sure, the seconds MDB, will get any results by your query?

like image 29
Christian Kuetbach Avatar answered Sep 23 '22 04:09

Christian Kuetbach