사용자 도구

사이트 도구


java:hibernate:usertype

차이

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

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
java:hibernate:usertype [2014/11/20 11:17]
kwon37xi [Hibernate User Type]
java:hibernate:usertype [2018/10/22 15:24]
kwon37xi
줄 5: 줄 5:
   * [[java:hibernate:usertype:stringboolean|StringBoolean Hibernate UserType]]   * [[java:hibernate:usertype:stringboolean|StringBoolean Hibernate UserType]]
   * UserType의 ''nullSafeSet''과 ''nullSafeGet''에서 값에 대한 로그를 ''trace'' 레벨로 남겨주어 쿼리 결과나 쿼리를 날릴 때의 로그로 해당 값을 Hibernate가 자동으로 남겨주는 다른 값들과 함께 로그로 남긴다.   * UserType의 ''nullSafeSet''과 ''nullSafeGet''에서 값에 대한 로그를 ''trace'' 레벨로 남겨주어 쿼리 결과나 쿼리를 날릴 때의 로그로 해당 값을 Hibernate가 자동으로 남겨주는 다른 값들과 함께 로그로 남긴다.
 +  * **''nullSafeGet''/''nullSafeSet''은 ''org.hibernate.type.StandardBasicTypes''의 실제 Type 상수에게 위임해주는 것이 좋다.**
 +    * 이 경우 굳이 UserType의 ''nullSafeGet/nullSafeSet''에서 로그를 안 남겨도 알아서 남는다.
 +  * [[https://github.com/jamesward/spring_hibernate_hstore_demo|Hibernate PostgresQL HStore]]
  
 ===== UserType의 등록 ===== ===== UserType의 등록 =====
줄 30: 줄 33:
 import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDef;
 import org.hibernate.annotations.TypeDefs; import org.hibernate.annotations.TypeDefs;
 +</code> <code java> 
 +// Entity class
 // 이제 엔티티 클래스에서는 다음과 같이 간단히 등록 가능 // 이제 엔티티 클래스에서는 다음과 같이 간단히 등록 가능
 @Type(type = "some_enum") @Type(type = "some_enum")
 @Column(name = "some_enum", length = 2, nullable = true) @Column(name = "some_enum", length = 2, nullable = true)
 private SomeEnum someEnum; private SomeEnum someEnum;
-</code> 
  
 +</code>
 ===== Primary Key ===== ===== Primary Key =====
   * Primary Key(Identifier)나  Descriminator(상속관계에서 구분자?)로 사용할 Custom Type은 ''org.hibernate.usertype.EnhancedUserType''를 구현해야 한다.   * Primary Key(Identifier)나  Descriminator(상속관계에서 구분자?)로 사용할 Custom Type은 ''org.hibernate.usertype.EnhancedUserType''를 구현해야 한다.
 +
 +===== 참고 =====
 +  * [[https://www.baeldung.com/hibernate-custom-types|Custom Types in Hibernate | Baeldung]]
  
java/hibernate/usertype.txt · 마지막으로 수정됨: 2018/10/24 10:26 저자 kwon37xi