사용자 도구

사이트 도구


java:hibernate:batch

차이

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

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
java:hibernate:batch [2018/12/11 16:32]
kwon37xi
java:hibernate:batch [2022/11/10 09:11]
kwon37xi [기억할 점]
줄 12: 줄 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://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 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. > 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
줄 63: 줄 67:
 ===== Versioned Data ===== ===== Versioned Data =====
   * ''hibernate.jdbc.batch_versioned_data=true'' 로 설정하면 ''@Version'' 컬럼에 대해 대응하여 배치가 실행된다. 자동으로 될 수도 있는데, 일반적으로 ''true''로 하는게 안전할 수 있다.   * ''hibernate.jdbc.batch_versioned_data=true'' 로 설정하면 ''@Version'' 컬럼에 대해 대응하여 배치가 실행된다. 자동으로 될 수도 있는데, 일반적으로 ''true''로 하는게 안전할 수 있다.
 +
 +===== 참조 =====
 +  * [[https://www.baeldung.com/jpa-hibernate-batch-insert-update|Batch Insert/Update with Hibernate/JPA | Baeldung]]
  
java/hibernate/batch.txt · 마지막으로 수정됨: 2022/11/13 23:13 저자 kwon37xi