Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring data JPA findFirst,findTop doesnt work

According to section 3.4.5 of the Spring Data JPA documentation, the results of a query method can be limited by using the keyword first and top.

I have written my code like this:

SysPrefixName findFirstByTableName(String tableName);

However, I get this error when I run the code:

result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements

Any help on resolving this will be appreciated.

like image 667
phxism Avatar asked Feb 25 '16 09:02

phxism


2 Answers

The support for those keywords was introduced in Spring Data JPA 1.7. See this ticket for details.

like image 177
Oliver Drotbohm Avatar answered Oct 22 '22 00:10

Oliver Drotbohm


This one worked for me:

public interface CashierRepository extends CrudRepository<Cashier, Integer>{
    List<Cashier> findAllByOrderByCashiergrouping();    
    Cashier findFirstBy();

}
like image 44
benizra Avatar answered Oct 22 '22 02:10

benizra