쿼리 한번으로 대량의 데이터를 수정할 때 사용
변경 감지가 일어나면서 update 쿼리가 나가는 것
개별 엔티티 건건이 나가는 것
@Commit
@DisplayName("bulkUpdate")
@Test
void bulkUpdate() {
//벌크 연산 전 DB
//member1 -> member1
//member2 -> member2
//member3 -> member3
//member4 -> member4
long count = jpaQueryFactory
.update(member)
.set(member.username, "비회원")
.where(member.age.lt(28))
.execute();
em.flush();
em.clear();
//벌크 연산 후 DB
//member1 -> 비회원
//member2 -> 비회원
//member3 -> member3
//member4 -> member4
List<Member> memberList = jpaQueryFactory
.selectFrom(member)
.fetch();
}
@DisplayName("bulkAdd")
@Test
void bulkAdd() {
long count1 = jpaQueryFactory
.update(member)
.set(member.age, member.age.add(1))
.execute();
long count2 = jpaQueryFactory
.update(member)
.set(member.age, member.age.multiply(2))
.execute();
}
@DisplayName("bulkDelete")
@Test
void bulkDelete() {
long count = jpaQueryFactory
.delete(member)
.where(member.age.gt(18))
.execute();
}