javax.persistence.NoResultException: No entity found for query

后端 未结 6 1545
再見小時候
再見小時候 2020-12-08 04:11

Before I posted this question, I already looked this, but I couldn\'t get what I was looking for.

I know that for the query I wrote there may exist only one row or n

6条回答
  •  甜味超标
    2020-12-08 04:23

    You mentioned getting the result list from the Query, since you don't know that there is a UniqueResult (hence the exception) you could use list and check the size?

    if (query.list().size() == 1) 
    

    Since you're not doing a get() to get your unique object a query will be executed whether you call uniqueResult or list.

提交回复
热议问题