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.
The support for those keywords was introduced in Spring Data JPA 1.7. See this ticket for details.
This one worked for me:
public interface CashierRepository extends CrudRepository<Cashier, Integer>{
List<Cashier> findAllByOrderByCashiergrouping();
Cashier findFirstBy();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With