I have Spring Repo class which look like this :
@Repository
public interface EmployeeRepository
extends CrudRepository<Employee, Long> {
@Query("Select s from Employee s where s.Id = ?1")
Optional<Employee> findEmployeeByID(String Id);
@Transactional
@Modifying
@Query(" How to DO that")
UpdateEmployeeDetails()
}
How to efficiently update the Employee details, as employee tables contains more than 15 fields i can't write a function for each of these fields, how we can generate a query which will have common logic to update
For Example :
If we want to update name only so UpdateEmployeeDetails() will execute this query :
UPDATE Employee SET firstName=UPPER(firstName) WHERE id in :ids
If we want to update name and address :
UPDATE Employee SET firstName=UPPER(firstName), Address = "Address" WHERE id in :ids
How we can do this efficiently as there are may fields so we want to generate query dynamically