사용자 도구

사이트 도구


java:hibernate:valuegenerator

차이

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

차이 보기로 링크

다음 판
이전 판
java:hibernate:valuegenerator [2021/10/07 21:19]
kwon37xi 만듦
java:hibernate:valuegenerator [2021/10/07 21:48] (현재)
kwon37xi [Example]
줄 2: 줄 2:
   * [[https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/annotations/GeneratorType.html|@GeneratorType]]과 [[https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/tuple/ValueGenerator.html|ValueGenerator ]] 조합으로 엔티티의 값(ID말고)을 원하는대로 자동 생성할 수 있다.   * [[https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/annotations/GeneratorType.html|@GeneratorType]]과 [[https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/tuple/ValueGenerator.html|ValueGenerator ]] 조합으로 엔티티의 값(ID말고)을 원하는대로 자동 생성할 수 있다.
  
 +
 +===== Example =====
 +<code java>
 +@Column(name = "created_by")
 +@GeneratorType(
 +    type = LoggedUserGenerator.class,
 +    when = GenerationTime.INSERT
 +)
 +private String createdBy;
 +---
 +// 생성기
 +// Hibernate session 으로 생성가능
 +public class LoggedUserGenerator
 +        implements ValueGenerator<String> {
 +    @Override
 +    public String generateValue(
 +            Session session, Object owner) {
 +        return LoggedUser.get();
 +    }
 +}
 +
 +</code>
  
 ===== 참조 ===== ===== 참조 =====
 +  * [[https://youtu.be/gkh1oojif60|Hibernate: How to Generate Values of Basic Entity Attributes
 +]]
   * [[https://vladmihalcea.com/how-to-emulate-createdby-and-lastmodifiedby-from-spring-data-using-the-generatortype-hibernate-annotation/|How to emulate @CreatedBy and @LastModifiedBy from Spring Data using the @GeneratorType Hibernate annotation - Vlad Mihalcea]]   * [[https://vladmihalcea.com/how-to-emulate-createdby-and-lastmodifiedby-from-spring-data-using-the-generatortype-hibernate-annotation/|How to emulate @CreatedBy and @LastModifiedBy from Spring Data using the @GeneratorType Hibernate annotation - Vlad Mihalcea]]
-  *  +  * [[https://www.greaterthan0.com/hibernate-generatortype-annotation-generating-custom-value-specific-property-or-column-or-attribute|Hibernate GeneratorType Annotation - Generating custom value for specific property or column or attribute | Greater Than 0]]
  
  
  
java/hibernate/valuegenerator.1633609180.txt.gz · 마지막으로 수정됨: 2021/10/07 21:19 저자 kwon37xi