oracle通过sequence定义触发器支持id的自增

sequence:s_author_id,从1开始步幅是1,最大值是999999999

-- Create sequence
create sequence S_AUTHOR_ID
minvalue
maxvalue
start with
increment by
cache ;

触发器:trg_authors

create or replace trigger trg_authors before insert on reader_resource_author for each row
begin
select s_author_id.nextval into :new.author_id from dual;
end;

java代码entity:

@Entity
@javax.persistence.SequenceGenerator(
name = "authorid",
sequenceName="s_author_id"
)
@Table(name = "reader_resource_author")
public class ResourceAuthor extends PersistentObject{ @Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="authorid")
@Column(name = "author_id")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
上一篇:24_Core Data Demo


下一篇:C#连接数据库时Appsettings 与connectionStrings的区别