Hibernate通过注解配置Oracle序列

1.创建Oracle序列

create sequence seq_id
increment by 1
start with 1
maxvalue 999999999;

2.在实体类主键的get方法上面添加注解

@Id
@SequenceGenerator(name="gen",sequenceName="SEQ_ID" ,allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="gen")
@Column(name = "id", unique = true, nullable = false)

备注:@SequenceGenerator的name可随意定义,sequenceName为创建的序列名称,@GeneratedValue的generator要与@SequenceGenerator的name值保持一致,表的主键需为NUMBER类型。

你可能感兴趣的:(Hibernate)