Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] javax.persistence.NoResultException

Woops my bad Leon, looks like getResultList() returns an empty List,
while getSingleResult() throws an exception, so a workaround would be
to use getResultList() and check the size of the list or simply catch
the runtimeexception for getSingleResult().

On Wed, May 14, 2008 at 12:42 PM, Tim Hollosy <hollosyt@xxxxxxxxx> wrote:
> Woops my bad Leon, looks like getResultList() returns an empty List,
> while getSingleResult() throws an exception, so a workaround would be
> to use getResultList() and check the size of the list or simply catch
> the runtimeexception for getSingleResult().
>
> On Wed, May 14, 2008 at 12:24 PM, Leon Derks <leon.derks@xxxxxxxxxx> wrote:
>> Hi Tim,
>>
>> It is on a JPA named query.
>>
>> Leon
>>
>> Tim Hollosy wrote:
>>>
>>> Is that on a native query or a JPQL query?
>>>
>>> I don't get it on a native query, I'd like to know when that exception
>>> is thrown though, in the mean time you could always catch the
>>> RuntimeException.
>>>
>>> /tim
>>>
>>> On Wed, May 14, 2008 at 12:03 PM, Leon Derks <leon.derks@xxxxxxxxxx>
>>> wrote:
>>>
>>>>
>>>> Hello
>>>>
>>>> I did get the following exception:
>>>> javax.persistence.NoResultException: getSingleResult() did not retrieve
>>>> any
>>>> entities.
>>>>
>>>> This exception is correct, because there was nu such object in the db.
>>>> But if the object doesn't exist, I want to return a null object and not a
>>>> NoResultException
>>>>
>>>> Is there a way how I can do that?
>>>>
>>>> Leon
>>>>
>>>>
>>>>  _______________________________________________
>>>> eclipselink-users mailing list
>>>> eclipselink-users@xxxxxxxxxxx
>>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>>
>>>>
>>>
>>>
>>>
>>>
>>
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>
>
>
> --
> ./tch
>



-- 
./tch


Back to the top