====== ValueGenerator ====== * [[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 ===== @Column(name = "created_by") @GeneratorType( type = LoggedUserGenerator.class, when = GenerationTime.INSERT ) private String createdBy; --- // 생성기 // Hibernate session 으로 생성가능 public class LoggedUserGenerator implements ValueGenerator { @Override public String generateValue( Session session, Object owner) { return LoggedUser.get(); } } ===== 참조 ===== * [[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://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]]