문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 | |||
|
java:hibernate:valuegenerationtype [2021/10/07 22:02] kwon37xi |
java:hibernate:valuegenerationtype [2021/10/07 22:04] (현재) kwon37xi [Example] |
||
|---|---|---|---|
| 줄 26: | 줄 26: | ||
| public @interface FunctionCreationTimestamp {} | public @interface FunctionCreationTimestamp {} | ||
| + | // DB를 통해 자동생성 지원 | ||
| public static class FunctionCreationValueGeneration | public static class FunctionCreationValueGeneration | ||
| implements AnnotationValueGeneration< | implements AnnotationValueGeneration< | ||
| 줄 65: | 줄 66: | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| + | 쿼리가 아래처럼 실행된다. | ||
| + | <code sql> | ||
| + | INSERT INTO Event (" | ||
| + | VALUES (current_timestamp, | ||
| </ | </ | ||
| + | <code java> | ||
| + | // In memory 상에서 자동생성 | ||
| + | public static class FunctionCreationValueGeneration | ||
| + | implements AnnotationValueGeneration< | ||
| + | |||
| + | @Override | ||
| + | public void initialize(FunctionCreationTimestamp annotation, Class<?> | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Generate value on INSERT | ||
| + | * @return when to generate the value | ||
| + | */ | ||
| + | public GenerationTiming getGenerationTiming() { | ||
| + | return GenerationTiming.INSERT; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Returns the in-memory generated value | ||
| + | * @return {@code true} | ||
| + | */ | ||
| + | public ValueGenerator<?> | ||
| + | return (session, owner) -> new Date( ); | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Returns false because the value is generated by the database. | ||
| + | * @return false | ||
| + | */ | ||
| + | public boolean referenceColumnInSql() { | ||
| + | return false; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Returns null because the value is generated in-memory. | ||
| + | * @return null | ||
| + | */ | ||
| + | public String getDatabaseGeneratedReferencedColumnValue() { | ||
| + | return null; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | 쿼리가 다음과 같이 날라간다. | ||
| + | <code sql> | ||
| + | INSERT INTO Event (" | ||
| + | VALUES ('Tue Mar 01 10:58:18 EET 2016', 1) | ||
| + | </ | ||