简体   繁体   中英

Spring data jpa findOne throwing IncorrectResultSizeDataAccessException exception

I am using spring data jpa and made a repository extending JpaSpecificationExecutor. Then I use findOne(specs) method. But I am getting this exception:

IncorrectResultSizeDataAccessException: query did not return a unique result: 2

Specs query does return more than one result, but I thought using findOne will return the first result? But I still receive error. I think I am using the wrong method. Which method should I use to get the first result?

findOne method assumes that your query will return only one row. So results that return more than one row will throw exception. Instead you can use findAll(...).get(0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM