Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloseableIterator errornously listed a supported repository return type #2835

Closed
sergey-morenets opened this issue May 28, 2023 · 1 comment
Assignees
Labels
type: documentation A documentation update

Comments

@sergey-morenets
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 28, 2023
@mp911de mp911de added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels May 30, 2023
@mp911de
Copy link
Member

mp911de commented May 30, 2023

Sorry for the confusion. CloseableIterator isn't supported as repository return type nor was it ever intended. It is a documentation bug where CloseableIterator sneaked into a change where it wasn't supposed to be listed in the first place.

@mp911de mp911de self-assigned this May 30, 2023
@mp911de mp911de changed the title Unable to use CloseableIterator in query methods CloseableIterator errornously listed a supported repository return type May 30, 2023
@mp911de mp911de added this to the 3.1.1 (2023.0.1) milestone May 30, 2023
@mp911de mp911de transferred this issue from spring-projects/spring-data-jpa May 30, 2023
mp911de added a commit that referenced this issue May 30, 2023
`CloseableIterator` wasn't intended to be here in the first place as it is only an intermediate type.

Closes #2835
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants