사용자 도구

사이트 도구


java:hibernate:valuegenerationtype

문서의 이전 판입니다!


Hibernate @ValueGenerationType

Example

@Entity(name = "Event")
public static class Event {
 
	@Id
	@GeneratedValue
	private Long id;
 
	@Column(name = "`timestamp`")
	@FunctionCreationTimestamp
	private Date timestamp;
 
	//Constructors, getters, and setters are omitted for brevity
}
 
@ValueGenerationType(generatedBy = FunctionCreationValueGeneration.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface FunctionCreationTimestamp {}
 
public static class FunctionCreationValueGeneration
		implements AnnotationValueGeneration<FunctionCreationTimestamp> {
 
	@Override
	public void initialize(FunctionCreationTimestamp annotation, Class<?> propertyType) {
	}
 
	/**
	 * Generate value on INSERT
	 * @return when to generate the value
	 */
	public GenerationTiming getGenerationTiming() {
		return GenerationTiming.INSERT;
	}
 
	/**
	 * Returns null because the value is generated by the database.
	 * @return null
	 */
	public ValueGenerator<?> getValueGenerator() {
		return null;
	}
 
	/**
	 * Returns true because the value is generated by the database.
	 * @return true
	 */
	public boolean referenceColumnInSql() {
		return true;
	}
 
	/**
	 * Returns the database-generated value
	 * @return database-generated value
	 */
	public String getDatabaseGeneratedReferencedColumnValue() {
		return "current_timestamp";
	}
}
java/hibernate/valuegenerationtype.1633611731.txt.gz · 마지막으로 수정됨: 2021/10/07 22:02 저자 kwon37xi