일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 그리디
- AOP
- 인프런
- 자바
- 알고리즘
- jpa
- QueryDSL
- 김영한
- Proxy
- Spring Boot
- JPQL
- Exception
- spring
- JDBC
- Servlet
- 백준
- transaction
- pointcut
- SpringBoot
- kotlin
- 스프링
- db
- Greedy
- Android
- java
- 스프링 핵심 원리
- http
- springdatajpa
- 스프링 핵심 기능
- Thymeleaf
- Today
- Total
목록bulk (2)
개발자되기 프로젝트
1. 쿼리 한번으로 대량 데이터 수정 : 벌크 연산 벌크연산은 영속성 컨텍스트를 거치지 않고 바로 DB에 반영함 즉 벌크연산 후 영속성 컨텍스트와 DB가 다르다. 벌크 연산 후 영속성 컨텍스트를 초기화 해주자. @Test public void bulkUpdate(){ /** * member1 = 10 -> 비회원 * member2 = 20 -> 비회원 * member3 = 30 -> 유지 * member4 = 40 -> 유지 */ long count = queryFactory .update(member) .set(member.username, "비회원") .where(member.age.lt(28)) .execute(); em.flush(); em.clear(); } update Member member..
예를들어 모든 인원의 나이를 하나 씩 올리거나, 연봉을 올리거나 할 때, 엔티티를 하나하나 불러와서 업데이트 하는 것 보다. DB에서 bulk로 변경하는 편이 적합하다. 1. JPA로 bulk 연산 executeUpdate()를 실행하면 업데이트, 삭데된 엔티티의 수를 반환. public int bulkAgePlus(int age){ return em.createQuery("update Member m set m.age = m.age + 1 where m.age >= :age") .setParameter("age", age) .executeUpdate(); //Returns: the number of entities updated or deleted } public int bulkAgePlus(int a..