Why in JPA EntityManager queries throw NoResultException but find does not?

后端 未结 4 1635
暗喜
暗喜 2020-12-10 02:48

Can somebody tell me the intrinsic reasons why in the JPA 1.0 EntityManager when retrieving an Object via find, you have to deal with null if not found, but when using the Q

4条回答
  •  既然无缘
    2020-12-10 03:34

    Queries can be used to retrieve almost anything including the value of a single column in a single row.

    If getSingleResult() would return null, you could not tell whether the query did not match any row or whether the query matched a row but the selected column contains null as its value.

提交回复
热议问题