zoukankan      html  css  js  c++  java
  • 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;
        }
    }        
  • 相关阅读:
    对软件工程的困惑
    团队作业(七)
    团队作业(六)
    团队作业(五)
    团队作业(四)
    团队作业(三)
    团队作业(二)
    团队作业(一)
    代码
    课余作业 采访
  • 原文地址:https://www.cnblogs.com/yanghuahui/p/3416277.html
Copyright © 2011-2022 走看看