QueryDsl: Updating table with two List parameters

Viewed 186

I have a method to update all employees, which is called for every single employee at service layer.

public void updateEmployeeData(Long id, String account) {
        queryFactory.update(employee)
                .set(employee.employeeAccount, account)
                .where(employee.employeeId.eq(id))
                .execute();
    }

I have to optimize code and call it once with the Lists parameters. For that reason I`ve turned id parameter into List.

public void updateEmployeeData(List<Long> ids, String account) {
        queryFactory.update(employee)
                .set(employee.employeeAccount, account)
                .where(employee.employeeId.in(ids))
                .execute();
    }

But how to iterate over each employees accounts? I cannot add IN clause to set part of query.

Is there any solution except enhanced For loop and iterating over every single employee?

1 Answers

In SQL you would use a temporary table or a values clause, but unfortunately these are not available in JPQL. It is not possible to update multiple rows with distinct values in a JPA modification query. Consecutively, Querydsl does not support this as it is merely a query builder around JPQL.

Related