사용자 도구

사이트 도구


java:hibernate:batch

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
java:hibernate:batch [2018/01/19 13:16]
kwon37xi [기본 설정]
java:hibernate:batch [2022/11/13 23:13] (현재)
kwon37xi
줄 5: 줄 5:
   * [[https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/Performance_Tuning_Guide/sect-Performance_Tuning_Guide-Entity_Beans-Batching_Database_Operations.html|Performance_Tuning_Guide-Entity_Beans-Batching_Database_Operations]]   * [[https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/Performance_Tuning_Guide/sect-Performance_Tuning_Guide-Entity_Beans-Batching_Database_Operations.html|Performance_Tuning_Guide-Entity_Beans-Batching_Database_Operations]]
   * [[https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/Performance_Tuning_Guide/sect-Performance_Tuning_Guide-Entity_Beans-Batch_Inserts.html|4.5.3. Batch Inserts]]   * [[https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/Performance_Tuning_Guide/sect-Performance_Tuning_Guide-Entity_Beans-Batch_Inserts.html|4.5.3. Batch Inserts]]
 +  * [[https://vladmihalcea.com/how-to-batch-insert-and-update-statements-with-hibernate/|How to batch INSERT and UPDATE statements with Hibernate - Vlad Mihalcea]]
  
 ===== 작동 원리 ===== ===== 작동 원리 =====
줄 11: 줄 12:
   * 기본적으로 ''addBatch/executeBatch''는 insert 성능을 향상시켜준다. [[http://java.dzone.com/articles/what-you-didnt-know-about-jdbc|What You Didn't Know About JDBC Batch]]   * 기본적으로 ''addBatch/executeBatch''는 insert 성능을 향상시켜준다. [[http://java.dzone.com/articles/what-you-didnt-know-about-jdbc|What You Didn't Know About JDBC Batch]]
  
-===== 기억할 점 =====+===== @Id 에 대한 주의점 =====
   * ''**GenerationType.IDENTITY**'' ID에 대해서는 Batch Insert가 **작동하지 않는다**. ID를 리턴받아 Entity 객체에 채워줘야 하기 때문으로 보인다.   * ''**GenerationType.IDENTITY**'' ID에 대해서는 Batch Insert가 **작동하지 않는다**. ID를 리턴받아 Entity 객체에 채워줘야 하기 때문으로 보인다.
 +    * [[https://vladmihalcea.com/jpa-persist-and-merge/|How do persist and merge work in JPA]]
 +    * [[https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#batch-session-batch-insert|Hibernate ORM 5.4.18.Final User Guide]]
 +  * 따라서 Batch Insert 를 올바로 작동시키려면 ''@GeneratedValue(strategy = GenerationType.SEQUENCE)'' 같은 PK 값을 미리 알 수 있는 방식을 사용해야한다.
 +
 +
 +> For IDENTITY columns, Hibernate cannot delay the INSERT statement until flush time because the identifier value can only be generated by executing the statement.
 +> For this reason, Hibernate disables JDBC batch inserts for entities using the IDENTITY generator strategy.
 +
 +===== 기억할 점 =====
   * batch 옵션은 Hibernate가 직접 Insert 문을 ''insert into xxx (...) values(...), (....), ....'' 형태로 합쳐주는 것이 **아니다**. 단지 ''addBatch''를 할 뿐이다.   * batch 옵션은 Hibernate가 직접 Insert 문을 ''insert into xxx (...) values(...), (....), ....'' 형태로 합쳐주는 것이 **아니다**. 단지 ''addBatch''를 할 뿐이다.
   * MySQL   * MySQL
줄 55: 줄 65:
 </code> </code>
  
 +===== Versioned Data =====
 +  * ''hibernate.jdbc.batch_versioned_data=true'' 로 설정하면 ''@Version'' 컬럼에 대해 대응하여 배치가 실행된다.
 +  * 즉, ''where'' 조건에 ''@Version'' 필드에 대한 조건이 들어간다.
 +  * 기본으로는 자동으로 될 수도 있는데, 일반적으로 ''true''로 하는게 안전할 수 있다.
 +  * 단, ''hibernate.jdbc.batch_versioned_data=true'' 일 경우 batch update 가 되긴하지만, 일부 JDBC 드라이버의 경우 업데이트된 필드 갯수를 오탐하는 경우도 있다고 한다. 이때는 ''false''로 바꿔야 하며, ''@Version'' 이 있을 경우 batch update 는 작동하지 않게 된다.
 +===== 참조 =====
 +  * [[https://www.baeldung.com/jpa-hibernate-batch-insert-update|Batch Insert/Update with Hibernate/JPA | Baeldung]]
 +  * [[https://techblog.woowahan.com/|MySQL 환경의 스프링부트에 하이버네이트 배치 설정 해보기 | 우아한형제들 기술블로그]]
java/hibernate/batch.1516337219.txt.gz · 마지막으로 수정됨: 2018/01/19 13:16 저자 kwon37xi