You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a Quarkus reactive with Panache project I have a Postgres DB that stores records in the table records. Each record has a version field, my app adds new rows for each role when something changes. Therefore I will have a collection of rows in this table representing the change history of each role (group rows by the field role). I would like a method to return the latest version of each role. This requires a native query:
SELECT*FROMtest.rolesJOIN (
SELECT DISTINCTON (role)
last_value(id) OVER wnd as last_id
FROMtest.roles WINDOW wnd AS (
PARTITION BY role ORDER BY version ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
)) as last
ON id = last_id;
This works fine if the table does not have linked entities (associations). Once I add such an association, e.g. an user field for the user that made the last change, the native query breaks. The association is defined like this on the class RoleEntity:
My native query throws java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 7 and I cannot get it to work. I traced this to ResultSetMappingImp::resolve where the fields/aliases are being built prior to returning a new JdbcValuesMappingImpl(...). First the fields of the "simple" fields of the RoleEntity class, and the last one is a long with index -2 in the aliases table. I empirically deduced that this is related to the linked UserEntity (if I remove that field it works as expected). Please help me write a native query for an entity with linked entities. Thank you!
A reproducer project is at https://github.com/thebe14/quarkus-native-query. It needs a Postgres DB with a schema called test in which it will create and populate the needed tables on first run with quarkus dev. You can use the Swagger-UI to try out the one and only API endpoint to cause the DB call.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
In a Quarkus reactive with Panache project I have a Postgres DB that stores records in the table records. Each record has a version field, my app adds new rows for each role when something changes. Therefore I will have a collection of rows in this table representing the change history of each role (group rows by the field role). I would like a method to return the latest version of each role. This requires a native query:
This works fine if the table does not have linked entities (associations). Once I add such an association, e.g. an user field for the user that made the last change, the native query breaks. The association is defined like this on the class
RoleEntity
:My native query throws
java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 7
and I cannot get it to work. I traced this toResultSetMappingImp::resolve
where the fields/aliases are being built prior to returning anew JdbcValuesMappingImpl(...)
. First the fields of the "simple" fields of theRoleEntity
class, and the last one is along
with index -2 in the aliases table. I empirically deduced that this is related to the linkedUserEntity
(if I remove that field it works as expected). Please help me write a native query for an entity with linked entities. Thank you!A reproducer project is at https://github.com/thebe14/quarkus-native-query. It needs a Postgres DB with a schema called test in which it will create and populate the needed tables on first run with
quarkus dev
. You can use the Swagger-UI to try out the one and only API endpoint to cause the DB call.Regards,
Levente
Beta Was this translation helpful? Give feedback.
All reactions