question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Stream as result of a query method failed due to expecting a singular result

See original GitHub issue

Despite what https://www.baeldung.com/spring-data-java-8 says, when I created a Stream<Foo> on a org.springframework.cloud.gcp.data.datastore.repository.DatastoreRepository implementation, I received this:

org.springframework.cloud.gcp.data.datastore.core.mapping.DatastoreDataException: The query method returns a singular object but the query returned more than one result.
  at org.springframework.cloud.gcp.data.datastore.repository.query.GqlDatastoreQuery.convertSingularResult (GqlDatastoreQuery.java:227)
  at org.springframework.cloud.gcp.data.datastore.repository.query.GqlDatastoreQuery.execute (GqlDatastoreQuery.java:156)
  at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke (RepositoryMethodInvoker.java:137)
  at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke (RepositoryMethodInvoker.java:121)
  at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke (QueryExecutorMethodInterceptor.java:152)
  at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke (QueryExecutorMethodInterceptor.java:131)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186)
  at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke (ExposeInvocationInterceptor.java:97)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (ReflectiveMethodInvocation.java:186)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke (JdkDynamicAopProxy.java:215)
  at com.sun.proxy.$Proxy104.getValidCarrierDirections (Unknown Source)
  • some investigation led me to org.springframework.data.repository.query.QueryMethod.isCollectionQuery()
  • then to org.springframework.data.repository.query.QueryMethod.calculateIsCollectionQuery()
  • then to org.springframework.data.util.TypeDiscoverer.isCollectionLike()

https://github.com/spring-projects/spring-data-commons/blob/main/src/main/java/org/springframework/data/util/TypeDiscoverer.java#L351-L359

Shouldn’t that list include java.util.stream.Stream?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mp911decommented, Apr 29, 2021

Iterable is the lowest common denominator across the collection framework. We’re actually considering to retrofit CrudRepository with Spring Data 3.0 to return List to make it easier to consume findAll and other methods returning collections.

0reactions
nbalicommented, Apr 29, 2021

Well, I was lucky then, to have worked mostly with projects where Iterable meant a streaming result. I mean without that extra functionality why would anybody return an Iterable, when you cuold just return a Collection/List instead?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Npgsql Exception while reading from stream, Postgres
I tried re-arranging the SQL to take out the sub-SELECTS and make them all joins; didn't help, same error. Here is the C#...
Read more >
Automated Re-fetching | Redux Toolkit
If cache data is being invalidated, it will either refetch the providing query (if components are still using that data) or remove the...
Read more >
Spring Data R2DBC - Reference Documentation
Limiting Query Results. You can limit the results of query methods by using the first or top keywords, which you can use interchangeably....
Read more >
Debugging errors - dbt Developer Hub
In some cases, these errors might occur as a result of queries that dbt runs "behind-the-scenes". These include: Introspective queries to list ...
Read more >
Solutions Engineer Senior Developer/Database ... - Ben Gribaudo
Streaming, query folding, buffering, table keys, native query caching and the firewall—all of these relate to how the interpreter thinks about/processes/handles ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found