JPA自定义主键生成策略

通常我们表的主键要么自增,要么使用uuid,插入数据库的时候是不需要手动来指定的,插入后会自动生成ID,但有些时候也不排除我们在插入前会手动指定ID,在JPA中该怎么做呢?
假设我们有如下两个实体类,员工 Employee 和 部门 Department 。他们的ID字段名称也不一样,分别是 empNo和deptNo。我们要在插入的时候手动指定他们的ID怎么办呢?

import cn.hutool.core.annotation.Alias;
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 lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.annotations.GenericGenerator;

@Data
@Accessors(chain = true)
@Entity
public class Employee implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Alias("id")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "employee_id")
    @GenericGenerator(name = "employee_id", strategy = "com.xxx.demo.generator.CustomerGenerator")
    private Integer empNo;

    private Date birthDate;

    private String firstName;

    private String lastName;

    private String gender;

    private Date hireDate;
}
import cn.hutool.core.annotation.Alias;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.Data;
import lombok.experimental.Accessors;
import org.hibernate.annotations.GenericGenerator;

@Data
@Accessors(chain = true)
@Entity
public class Department implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Alias("id")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "department_id")
    @GenericGenerator(name = "department_id", strategy = "com.xxx.demo.generator.CustomerGenerator")
    private String deptNo;

    private String deptName;
}
import cn.hutool.core.util.ReflectUtil;
import java.io.Serializable;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentityGenerator;

public class CustomerGenerator extends IdentityGenerator {

    @Override
    public Serializable generate(SharedSessionContractImplementor session, Object object) {
        Object id = ReflectUtil.getFieldValue(object, "id");
        if (id != null) {
            return (Serializable) id;
        }
        return super.generate(session, object);
    }
}