Skip to content

setHint does not work with updateAllStatement #2404

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

Open
fabiohecht opened this issue Apr 17, 2025 · 3 comments
Open

setHint does not work with updateAllStatement #2404

fabiohecht opened this issue Apr 17, 2025 · 3 comments

Comments

@fabiohecht
Copy link

fabiohecht commented Apr 17, 2025

Hi there, I'm trying to use setHint with updateAllStatement but the hint does not get copied to the SQL statement.

I believe a updateAllStatement.setHintString(getQuery().getHintString()); is missing around this part:

Can someone please confirm?

Here is my code in case anyone is interested:

    Query bulkAssignUnassigned = entityManager().createQuery(""
            + "UPDATE Message e"
            + "   SET e.handlerId.value = :handlerId,"
            + "       e.modifiedStamp = :currentTimeStamp,"
            + "       e.version = e.version + 1"
            + " WHERE e.id IN :ids"
            + "   AND e.status IN :acceptableStatus"
            + "   AND e.handlerId IS NULL"
        )
        .setParameter("handlerId", handlerId.value())
        .setParameter("currentTimeStamp", ZonedDateTime.now())
        .setParameter("ids", ids)
        .setParameter("acceptableStatus", acceptableStatus)
        .setHint(HINT, "/*+ INDEX (T_MESSAGE I_PK_DIMSGI_ID) */");
    int updateCount = bulkAssignUnassigned.executeUpdate();

Cheers,

Fabio

@AleksNo
Copy link

AleksNo commented Apr 22, 2025

Hi, TypedQuery.setHint(String, Object) is not meant to pass hints to the SQL server. It is meant to pass hints to Eclipselink itself. If you want to pass hints to the SQL server then put them into the SQL statement.

@fabiohecht
Copy link
Author

Hi @AleksNo , thanks for looking into it.

I tried putting the hint into the query and I get an error message:

Exception Description: Syntax error parsing [UPDATE /*+ INDEX (T_MESSAGE I_PK_DIMSGI_ID) */ Message e   SET e.handlerId.value = :handlerId,... 
[9, 9] The SET identifier is missing from the UPDATE clause.
[8, 9] The identification variable '*' cannot be a reserved word.
[42, 42] The equal sign must be specified.
[9, 41]  The expression is invalid, which means it does not follow the JPQL grammar.
[57, 411] The query contains a malformed ending.

I also tried the hint before "UPDATE" to no avail. I believe right now my only chance would be to use a native query, which would be a pity.

When looking at the source code, to try and understand why my other hints do get passed to the SQL Server (Oracle in my case) but the hint for this specific query does not, I can see that the hint is copied for delete, insert, select and update statements, but not for updateAll. Thus, it looks to me that it is missing. But maybe there is a good reason for that, which I don't understand.

SQLDeleteStatement:

SQLInsertStatement:

SQLSelectStatement:

SQLUpdateStatement:

SQLUpdateAllStatement: missing

@fabiohecht
Copy link
Author

@AleksNo can you please have a look, I'm pretty sure the hint does get passed to the queries for every statement, except the SQLUpdateAllStatement, or am I missing something?

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

No branches or pull requests

2 participants