Create primary key in Oracle and use in Spring data JPA

In Oracle:

  Create a sequence  

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

  SQL statement to get the sequence

select seq_newsid.nextval from sys.dual;

  SQL to delete a sequence

DROP SEQUENCE seq_newsId;

In this way, the sequence in Oracle is created.

In Jpa:

  Entity class configuration

 1 @Id
 2 
 3  @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="mseq")
 4 
 5  @SequenceGenerator(name="mseq",sequenceName="seq_newsId",allocationSize=1)
 6 
 7  @Column(name = "ENTID", unique = true, nullable = false, precision = 22, scale = 0)
 8 
 9  public long getEntid() {
10 
11   return this.entid;
12 
13  }

sequenceName is the sequence created by itself in oracle. allocationSize must be specified as 1, otherwise it will grow by the default 50 numbers.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325078633&siteId=291194637