I write a query to update a customer record as native query in jpa but unable to get response. it giving me some irrelevant responses
@Query(value = "UPDATE CUSTOMER SET NAME = :name, PHONE = :phone")
Customer updateWithNameAndPhone(@Param("name") String name, @Param("phone") String phone)
To show that the query updates the database, use the @Modifying annotation. To indicate that the query is a native SQL query, provide the nativeQuery = true argument. The updated customer object is not required as a return value, hence the void return type is used. You can switch the return type to Customer and adjust the function implementation if you wish to get the updated customer object.
@Query(value = "UPDATE CUSTOMER SET NAME = :name, PHONE = :phone WHERE CUSTOMER_ID = :customerId", nativeQuery = true)
@Modifying
void updateCustomerWithNameAndPhone(@Param("name") String name, @Param("phone") String phone, @Param("customerId") Long customerId);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With