-
Notifications
You must be signed in to change notification settings - Fork 693
Closed
Labels
type: documentationA documentation updateA documentation update
Milestone
Description
Hi
According to Spring Data JPA reference documentation query methods can return List, Stream, Streamable or CloseableIterator.
The first three types are handled correctly but the fourth type raises an error.
We created repository:
public interface ProductRepository extends
JpaRepository<Product, Integer>, JpaSpecificationExecutor<Product> {
CloseableIterator<Product> findByPrice(double price);
And while trying to fetch the entities:
CloseableIterator<Product> iterator =
productRepository.findByPrice(20);
while(iterator.hasNext()) {
System.out.println(iterator.next());
}
we receive an exception:
Caused by: jakarta.persistence.NonUniqueResultException: query did not return a unique result: 20
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:128)
at org.hibernate.query.spi.AbstractSelectionQuery.getSingleResult(AbstractSelectionQuery.java:482)
at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:223)
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:92)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:148)
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:136)
Spring Data JPA 3.1.0
Metadata
Metadata
Assignees
Labels
type: documentationA documentation updateA documentation update