사용자 도구

사이트 도구


java:hibernate:configuration

차이

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

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
java:hibernate:configuration [2016/09/24 15:01]
kwon37xi
java:hibernate:configuration [2023/07/03 14:53] (현재)
kwon37xi [hibernate.query.fail_on_pagination_over_collection_fetch]
줄 1: 줄 1:
 ====== Hibernate Configurations ====== ====== Hibernate Configurations ======
-  * http://docs.jboss.org/hibernate/core/3.5/reference/en/html/session-configuration.html 
   * hibernate properties, property   * hibernate properties, property
-====== hibernate.hbm2ddl.auto 프라퍼티 ======+  * [[https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java|org.hibernate.cfg.AvailableSettings]] 설정 상수 모음 
 +  * [[https://github.com/hibernate/hibernate-orm/blob/main/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java|org.hibernate.cfg.Environemnt]] 설정 상수 모음 
 +===== hibernate.hbm2ddl.auto 프라퍼티 =====
   * http://gyumee.egloos.com/2483659 참조.   * http://gyumee.egloos.com/2483659 참조.
-  * create : Session factory가 실행될 때에 스키마를 지우고 다시 생성. 클래스패스에 import.sql 이 존재하면 찾아서, 해당 SQL도 함께 실행함. +  * [[https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/tool/schema/Action.html|schema Action]] 
-  * create-drop : create와 같지만 session factory가 내려갈 때 스키마 삭제. +  * ''create-only'' : 생성만하고, drop은 하지 않는다. 개발 모드에서 최초에 한 번 이걸로 실행하고, 다음에는 ''update''로 변경하면 될 듯. Hibernate 5.2 이상에서만 지원하는 것으로 보임. 
-  * update : 시작시, 도메인과 스키마 비교하여 필요한 컬럼 추가 등의 작업 실행. 데이터는 삭제하지 않음. +  * ''create'' : Session factory가 실행될 때에 스키마를 지우고 다시 생성. 클래스패스에 import.sql 이 존재하면 찾아서, 해당 SQL도 함께 실행함. 
-  * validate : Session factory 실행시 스키마가 적합한지 검사함. 문제가 있으면 예외 발생.+  * ''create-drop'' : create와 같지만 session factory가 내려갈 때 스키마 삭제. 클래스패스에 import.sql 이 존재하면 찾아서, 해당 SQL도 함께 실행함
 +  * ''update'' : 시작시, 도메인과 스키마 비교하여 필요한 컬럼 추가 등의 작업 실행. 데이터는 삭제하지 않음. 
 +  * ''validate'' : Session factory 실행시 스키마가 적합한지 검사함. 문제가 있으면 예외 발생.
  
   * 개발시에는 create가, 운영시에는 auto 설정을 빼거나 validate 정도로 두는 것이 좋아 보인다. update로 둘 경우에, 개발자들의 스키마가 마구 꼬여서 결국은 drop 해서 새로 만들어야 하는 사태가 발생한다.   * 개발시에는 create가, 운영시에는 auto 설정을 빼거나 validate 정도로 두는 것이 좋아 보인다. update로 둘 경우에, 개발자들의 스키마가 마구 꼬여서 결국은 drop 해서 새로 만들어야 하는 사태가 발생한다.
  
-====== hibernate.use_sql_comments 프라퍼티 ======+===== hibernate.use_sql_comments 프라퍼티 =====
   * Native SQL 쿼리로 변환할 때 쿼리에 대한 주석을 함께 달아준다.   * Native SQL 쿼리로 변환할 때 쿼리에 대한 주석을 함께 달아준다.
  
-====== hibernate.jdbc.time_zone ======+===== hibernate.jdbc.time_zone =====
   * [[http://in.relation.to/2016/09/12/jdbc-time-zone-configuration-property/|How to store timestamps in UTC using the new hibernate.jdbc.time_zone configuration property]]   * [[http://in.relation.to/2016/09/12/jdbc-time-zone-configuration-property/|How to store timestamps in UTC using the new hibernate.jdbc.time_zone configuration property]]
 +  * Hibernate 5.2.3 부터 Timestamp, Calendar 저장시 원하는 Timezone 으로 저장하도록 할 수 있다.
 +<code java>
 +settings.put(
 +    AvailableSettings.JDBC_TIME_ZONE,
 +    TimeZone.getTimeZone( "UTC" )
 +);
 +
 +// or
 +Session session = sessionFactory()
 +    .withOptions()
 +    .jdbcTimeZone( TimeZone.getTimeZone( "UTC" ) )
 +    .openSession();
 +</code>
 +
 +===== hibernate.temp.use_jdbc_metadata_defaults =====
 +  * DB Sharding 처리를 Spring 차원에서 하고자할 때 ''hibernate.temp.use_jdbc_metadata_defaults=false''로 두어야 한다.
 +  * [[http://stackoverflow.com/questions/10075081/hibernate-slow-to-acquire-postgres-connection|java - Hibernate Slow to Acquire Postgres Connection - Stack Overflow]]
 +  * Hibernate 4 ''JdbcServicesImpl.java'' 주석.<code java>
 +// 'hibernate.temp.use_jdbc_metadata_defaults' is a temporary magic value.
 + // The need for it is intended to be alleviated with future development, thus it is
 + // not defined as an Environment constant...
 + //
 + // it is used to control whether we should consult the JDBC metadata to determine
 + // certain Settings default values; it is useful to *not* do this when the database
 + // may not be available (mainly in tools usage).
 + boolean useJdbcMetadata = ConfigurationHelper.getBoolean( "hibernate.temp.use_jdbc_metadata_defaults", configValues, true );
 +</code>
 +
 +===== hibernate.enable_lazy_load_no_trans=true 금지 =====
 +  * ''hibernate.enable_lazy_load_no_trans=true|false'' 사용하지 말 것. Open Session In View와 비슷한 역할.
 +  * [[https://vladmihalcea.com/the-hibernate-enable_lazy_load_no_trans-anti-pattern/|The hibernate.enable_lazy_load_no_trans Anti-Pattern]]
 +
 +===== hibernate.globally_quoted_identifiers=true =====
 +<code>
 +hibernate.globally_quoted_identifiers=true
 +hibernate.globally_quoted_identifiers_skip_column_definitions=true
 +</code>
 +
 +  * column, table 이름 등이 DB의 keyword 와 충돌할 때 대비하여 기본적으로 quote 시켜준다. DB별로 다른 quote 사용.
 +  * 단, ''columnDefinition''에 있는 단어도 함께 escape 시켜버리는데, 이것을 방지하는게 ''hibernate.globally_quoted_identifiers_skip_column_definitions=true'' 프라퍼티이다.
 +  * [[https://vladmihalcea.com/escape-sql-reserved-keywords-jpa-hibernate/|How to escape SQL reserved keywords with JPA and Hibernate - Vlad Mihalcea]]
 +
 +===== hibernate.query.in_clause_parameter_padding =====
 +===== hibernate.query.plan_cache_max_size =====
 +  * [[java:hibernate:performance|Hibernate Performance Tuning]] 참조
 +
 +===== hibernate.query.fail_on_pagination_over_collection_fetch =====
 +  * [[https://vladmihalcea.com/hibernate-query-fail-on-pagination-over-collection-fetch/|How to detect HHH000104 issues with hibernate.query.fail_on_pagination_over_collection_fetch - Vlad Mihalcea]]
 +  * ''5.2.13'' 버전 이후 설정 가능. 
 +  * **To-Many** 관계를  join fetch 하게 되면 Many 측 관계로 인해서 정확한 갯수로 제약을 줄 수 없다. 이로 인해 하이버네이트는 모든 데이터를 다 가져온 뒤에 메모리에서 정렬하여 원하는 갯수만 획득하게 된다.
 +  * 이는 심각한 메모리 문제, 성능 저하를 일으키게 된다.
 +  * Hibernate 은 이 ''to-many'' 관계의 join fetch 에 대해 ''warning'' 로그를 남기지만 이것은 발견하기 매우 어렵다.
 +  * ''hibernate.query.fail_on_pagination_over_collection_fetch=true'' 설정을 하면 아예 exception 을 발생시키게 된다.
 +  * 항상 활성화하고 미리 에러를 잡는게 낫다.
 +
 +<code>
 +hibernate.query.fail_on_pagination_over_collection_fetch=true
 +</code>
java/hibernate/configuration.1474698692.txt.gz · 마지막으로 수정됨: 2016/09/24 15:01 저자 kwon37xi