2

With spring data JPA if i write query like this:

@Query("update User u set  u.firstName=?1 where u.id=?2")
Integer updateFirstName(String firstName,String id);

updateFirstName method return either 0 or 1 based on update. But in spring data cassandra with this query:

@Query("update User set  firstName=?0 where id=?1")
Integer updateFirstName(String firstName,String id);

I am getting null . Is there is any way i can get confirmation that update operation is completed successfully.

2 Answers 2

2

Calling arbitrary CQL using query methods is possible but you need to align the return type (e.g. Row). Also, an UPDATE command does not return any rows hence you won't receive any result.

The confirmation that your call was successful is the normal termination of the query method.

Sign up to request clarification or add additional context in comments.

1 Comment

I have updated my query to this: @Query("update User set firstName=?0 where id=?1") Row updateFirstName(String firstName,String id); but i am getting this execution: java.lang.IllegalArgumentException: Entity must not be null!
1

@Query is used in Spring Data to select the values from the DB.

You can use the @Modifying along with @Query, which will trigger at the annotated method an "update query" instead of a "select one".

So the final form of that would be:

@Modifying
@Query("update User set firstName=?0 where id=?1")
Integer updateFirstName(String firstName,String id);

1 Comment

@Modifying annotation is not available in spring-data-cassandra

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.