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

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

Merged
merged 3 commits into from
Nov 23, 2023

Conversation

DavideD
Copy link
Member

@DavideD DavideD commented Nov 23, 2023

Same as #1797
but for the 2.0 branch

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.
@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Nov 23, 2023

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@DavideD DavideD changed the title T Throw an exception if query doesn't have a result but we expect one #1797 Nov 23, 2023
@DavideD DavideD merged commit 684f317 into hibernate:2.0 Nov 23, 2023
29 of 30 checks passed
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.

None yet

1 participant