Skip to content

Unable to run named query to get sequence current/next value #3934

Closed as not planned
@pentolone

Description

@pentolone

Jakarta persistence 3.1.0
SpringBoot 3.5.+
Database SAP Hana HDB 2.0
Hibernate 6.6.18.Final
Java 17

I am writing to get current value/next value for generated sequences.
The correct way to get sequences in Hana are:

SELECT <schema name>."<sequence name>".CURRVAL from DUMMY to get the current value of a sequence
SELECT <schema name>."<sequence name>".NEXTVAL from DUMMY to get the next value of a sequence

In Hana double quotes around sequence name are mandatory

This is the code I try to use:
String sequenceNameTag = "_sequence";
String getCurrentSapHanaSequence= "SELECT {h-schema}:" + sequenceNameTag + ".CURRVAL FROM DUMMY";

@Query(value = getCurrentSapHanaSequence, nativeQuery = true) Long getCurrentSequenceSapHana( @Param(sequenceNameTag ) String sequenceName );

This is the response:
No argument for named parameter ':_sequence.CURRVAL'

The same behaviour trying to get NEXTVAL.

I also tried to add double quote around sequence name, but raises an sql syntax exception and the query is not fired.
I don't know if there is a way to make these queries run properly.
Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions