문서의 이전 판입니다!
join fetch
를 통해서 (inner join등 명시) N + 1 대신에 미리 join 문으로 객체를 로딩할 수 있다.
batch-size
설정은 OneToMany 등의 관계에서 Many쪽 Lazy Proxy 객체를 로딩할때, 한번에 로딩할 갯수를 지정한다.
예를들면 Cat 객체가 Kitten 객체의 리스트를 Lazy로 가지고 있을 때 List<Cat>
을 돌면서 getKittens()
를 실행하면 각각의 Cat에 대해 한번씩 쿼리가 날라간다.(n + 1 problem)
하지만 @BatchSize(size = 10)
처럼 해당 관계에 설정을 해 두면, Kitten 객체를 로딩할 때 Cat id 10개씩 in
Query로 한번에 로딩한다.
hibernate.default_batch_fetch_size=100
프라퍼티 형태로 일괄 지정도 가능하다.TBD
auto commit=false
을 항상 켜고, Hibernate 에서 직접 auto commit=false
하는 것을 막아서 불필요한 setAutoCommit()
호출로 인한 성능 저하를 줄이기auto-commit: false
로 지정. 이걸 true
로 해버리면 트랜잭션이 안 먹음.hibernate.connection.provider_disables_autocommit: true
로 지정 : 커넥션 풀의 autocommit 을 무조건 따르겠다는 의미. 5.2.10
이상 버전auto-commit
설정값에 따라 자동으로 hibernate.connection.provider_disables_autocommit: true
설정을 해준다. HibernateJpaConfiguration.java
if (!vendorProperties.containsKey(PROVIDER_DISABLES_AUTOCOMMIT)) { configureProviderDisablesAutocommit(vendorProperties); } ... if (isDataSourceAutoCommitDisabled() && !isJta()) { vendorProperties.put(PROVIDER_DISABLES_AUTOCOMMIT, "true"); }
in Hibernate 5.2.10, we introduced the hibernate.connection.provider_disables_autocommit configuration property which tells Hibernate that the underlying JDBC Connections already disabled the auto-commit mode.