你不能。该生成器仅适用于标识符列。
确保使用脚本(例如hibernate.hbm2ddl.import_files
)创建此序列:
create sequence subscription_code_1_seq start 1 increment 7
然后使用如下映射:
@Id @SequenceGenerator( name="subscription_id_seq", sequenceName="subscription_id_seq", allocationSize=7 ) @GeneratedValue( strategy=GenerationType.SEQUENCE, generator="subscription_id_seq" ) @Column(unique=true, nullable=false) private Integer id; @Column( name="code", nullable=false, unique=true, insertable = false, updatable = false, columnDefinition = "BIGINT DEFAULT nextval('subscription_code_1_seq')" ) @Generated(GenerationTime.INSERT) private Integer code;