oracle通過sequence定義觸發器支持id的自增


sequence:s_author_id,從1開始步幅是1,最大值是999999999

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

觸發器: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;
    }
}        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM