No entity found for query Exception

前端 未结 3 1164
不思量自难忘°
不思量自难忘° 2020-12-29 04:24

I am executing the following lines:

  String queString = \"some query string\"
  Query q1 = em.createNativeQuery(queString, T03CallsLog.class);
  T03CallsLog         


        
相关标签:
3条回答
  • 2020-12-29 04:29

    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.
    
    0 讨论(0)
  • 2020-12-29 04:29

    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?

    0 讨论(0)
  • 2020-12-29 04:31

    Hibernate

    The more specific entityManager in hibernate is the HibernateEntityManager. If you instead of

    @PersistenceContext
    public final EntityManager em = null;
    

    Use the more specific

    @PersistenceContext
    public final HibernateEntityManager em = null;
    

    Then you could use the

    String queString = "some query string"
    Iterator<T03CallsLog> q1 = em.createNativeQuery(queString, T03CallsLog.class).iterate();
    T03CallsLog newCall = q1.hasNext() ? q1.next() : null;
    
    0 讨论(0)
提交回复
热议问题