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

@query not working for an update statement? #297

Open
DNWEIJ opened this issue May 9, 2023 · 0 comments
Open

@query not working for an update statement? #297

DNWEIJ opened this issue May 9, 2023 · 0 comments

Comments

@DNWEIJ
Copy link

DNWEIJ commented May 9, 2023

I am trying to do an update @query, this fails

Using @query for update statements should work imho, I could not find some documentation that the @query cannot be used for update statements from spring-data-hazelcast, but could also not find an example.
From the hazelcast docs it states that update sql should work.

Question: Should it be possible to do a @query with an UPDATE statement?

During debugging, i found the following info:

Using a statement like:
@query("UPDATE table set field = '%s' WHERE id = '%d' ")

Isn't working due to some code issues I have found. I have listed some points that can be improved/enhanced to ensure an update statement can be proecessed. I think the whole parsing etc is only build for select not for updates...

Some points I found, debuggin the code:

SqlParser:
        if (token.equals(")")) { 
```
I am not fully understaning why the whole sqlparser is done. 
THe first step actually already defines the sql that should be able to work.
`StringBasedHazelcastRepositoryQuery:execute`
shows the queryString, that seems to be already sql that would be executed. 

Beside that, the processing of the SqlParser isn't handling "(" correclty, in the sense that for the UPDATE it is using the stack and this means the actual token list is wrongly defined. 

Next to that the `SqlPRedicate` isn't working as well. The `createComparison EQUAL_FACTORY`  isn't indexing the token list correctly



```
StringBasedHazelcastRepositoryQuery::execute
  String queryString = String.format(queryStringTemplate, formatParameters(parameters));
```
Using String format is a bit limiting, but works if used correctly within the @Query statement.
Would be nicer to support something like parameters:
```
@Query("select u from User u where u.firstname = :firstname")
List<User> findUsersByCustomersFirstname(@Param("firstname")String firstName);
```
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

1 participant