-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Switch to JPA 3.2 Query.getSingleResultOrNull()
#3701
Comments
Care to elaborate? There should be no logging involved from our side. Looking at the |
I've clarified the issue with a link (which I've found meanwhile) to an opentelemtry issue. |
This ticket is a duplicate of #3633 |
Ok, the linked ticket has a much better description of the underlying OTEL problem. Still, I would like to understand why it wouldn't be possible to replace the current |
We comply with the JPA spec by using |
Can you please point me to a guideline that mandates that you must use |
From the Javadoc:
and for
Going forward, the spec mentions:
With JPA 3.2, we can switch to |
Yes, I read that doc snippets. And I see nothing in them that would indicate that using getResultList in your case is wrong or unsafe (assuming, of course, that providers implement the specification correctly). Anyway, looks like |
Query. getSingleResultOrNull()
Query. getSingleResultOrNull()
Query.getSingleResultOrNull()
Alright, I repurposed this ticket and marked it for inclusion for our |
We now use getSingleResultOrNull() to avoid NoResultException handling. Closes #3701
We now use getSingleResultOrNull() to avoid NoResultException handling. Closes #3701
I'm talking about this code: https://github.com/spring-projects/spring-data-jpa/blob/main/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java#L224. As we know,
getSingleResult
throws an exception upon a non-existing entity. Since this is an allowed situation the exception is caught here https://github.com/spring-projects/spring-data-jpa/blob/main/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryExecution.java#L92.I wonder why this try/catch approach (generally frowned upon) is used here instead of an alternative approach using
getResultList
, see e.g. https://stackoverflow.com/a/2885024/13015027. Apart from a slight performance penalty (not measured), the biggest problem of the current approach is that the exception is captured by telemetry agents (see open-telemetry/opentelemetry-java-instrumentation#12125).The text was updated successfully, but these errors were encountered: