Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

data-jpa: throwing some exception when result is null

$
0
0
Hi,

I was wondering if there was an option in spring-data-jpa to throw an exception when a query returns null.

For example, if I have a @Repository with a method "User findByEmail(String email)", I would like the method to throw something like NoSuchElementException|EntityNotFoundException|Wha teverException if there is no result.

This would allow me to have a spring mvc @ControllerAdvice with a @ExceptionHandler({NoSuchElementException.class,En tityNotFoundException.class,WhateverException.clas s}) which would send a 404 error.

If there is no such feature, do other people think it would be nice to have? I would propose to have get* methods instead of find* methods that would throw those exceptions.

Thanks,

Viewing all articles
Browse latest Browse all 297

Trending Articles