jpa之指定生成主键

package com.cjhd.fruit.database.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import lombok.Data;

@Entity
@Data
@Table(name = "test")
public class Test implements Serializable{

    private static final long serialVersionUID = -5672376456830499495L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "test")
    @SequenceGenerator(initialValue = 10000, name = "test", sequenceName = "TEST_SEQUENCE")
    private long id;
    
    private String name;
    
    /** 创建时间 */
    @Temporal(TemporalType.TIMESTAMP)
    @CreationTimestamp
    private Date createTime;

    /** 最后数据更新时间 */
    @Temporal(TemporalType.TIMESTAMP)
    @UpdateTimestamp
    private Date updateTime;

    public static Test valueOf(String name) {
        Test test = new Test();
        test.name = name;
        return test;
    }
}

 

上一篇:原创:微信小程序亲测体验,公众号入口曝光!


下一篇:微信企业号 JS-SDK:上传图片