Skip to content

Throw an exception if query doesn't have a result but we expect one #1797

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

Merged
merged 4 commits into from
Nov 23, 2023

Conversation

DavideD
Copy link
Member

@DavideD DavideD commented Nov 23, 2023

Fix #1792

…ults

It should get thrown when a user call `.getSingleResultOrNull()` but
the SQL query doesn't return any result. For example, when creating a
stored procedure in PosgtreSQL
When running a native query that doesn't return any result (for example,
the creation of a stored procedure), `io.vertx.sqlclient.SqlResult#columnsNames` will be null.

This commit doesn two things:
1. add null check to avoid a NPE if `.columnsNames` returns null;
2. Throw an HibernateException if the user call getSingleResultOrNull
   but the query doesn't return any result.

   Note that we could return null in this situation, but we've decided
   to be consistent with Hibernate ORM, where the JDBC driver will throw
   the following exception (with PostgreSQL at least):
   ```
   Caused by: org.postgresql.util.PSQLException: No results were returned by the query.
	at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:135)
	at org.hibernate.sql.results.jdbc.internal.DeferredResultSetAccess.executeQuery(DeferredResultSetAccess.java:240)
   ```
We are checking that it doesn't throw a NullPointerException
if the result of the query doesn't have any columns names.
@DavideD DavideD merged commit 502e971 into hibernate:main Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

java.lang.NullPointerException: Cannot invoke "java.util.List.size()" because the return value of "io.vertx.sqlclient.RowSet.columnsNames()" is null
1 participant