Add exceptions to native queries in Spring Data JPA

Viewed 1022

I am currently using a native query for selecting an entity from the join of multiple tables.

 public interface POrderRepository extends CRUDRepository<POrder, long>

 @Query("SELECT order_a.column_a, order_b.column_b from order_a inner join order_b on order_a.column_x = order_b.column_y")
 ArrayList<POrder> readAllPOrders();

I would like this method to also throw EmptyResultSetDataAccessException, wrapped in a DataAccessException in case nothing is found. As I understand, this is the default behaviour for the CRUD operations provided by CRUDRepository methods such as findall.

How can I go about achieving the same?

0 Answers
Related