Query with RETURNING statement crashes due to using executeUpdate instead of execute
Expected Behavior
The query should return the updated rows.
This seems to have been fixed a long time ago but might have broken at some point since.
Actual Behaviour
Crashes with Error executing SQL UPDATE: A result was returned when none was expected
Steps To Reproduce
- Create a db and a table.
- Create a repository with a method with the following kind of query
@Query(value = "update ... where ... returning *", readOnly = false) - Insert some data
- Call the method
Environment Information
OS: macOS Monterey 12.4, Windows 10 19044.1706 JDK: OpenJDK 17+35-2724
Example Application
https://github.com/Dattish/micronaut-data-repro
Version
3.5.1
The referenced issue has a simple query so it works but the update is a different thing. We would need to add a bit different API to support this kind of return.
I am also running into this issue. Any status update on this?
Hi, we are also running into this issue. This has been open for more than a year! Any updates or workarounds would be helpful. Thanks!
Same here, it's still not fixed
If you are using the 3.x releases and want to workaround this issue, you can do the following query instead:
WITH realQuery AS (
UPDATE/INSERT/DELETE ..
RETURNING ...
)
SELECT ... FROM realQuery
...
You'll need to mark the method @Transactional and you can even do extra operations, such as aggregation, in the select, that are not allowed with RETURNING.