Fork me on GitHub

【01-14】hibernate时间生成


package rugal.sample.core.entity;

import java.util.Date;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "tbl_time_test")
public class CreateTimeTest {

	@Id
	@GenericGenerator(name = "UUIDGENERATE", strategy = "uuid2")
	@GeneratedValue(generator = "UUIDGENERATE")
	@Column(name = "id")
	private UUID id;

	/**
	 * 指定insert时自动插入
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "create_time", updatable = false)
	@org.hibernate.annotations.CreationTimestamp
	private Date createTime;

	/**
	 * 指定update时自动更新
	 */
	@Column(name = "update_time")
	@org.hibernate.annotations.UpdateTimestamp
	@Temporal(TemporalType.TIMESTAMP)
	private Date updateTime;

	public UUID getId() {
		return id;
	}

	public void setId(UUID id) {
		this.id = id;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}
}

posted @ 2017-01-14 23:26  aloha_world  阅读(137)  评论(0编辑  收藏  举报