How to increment the the primary key of a table using a sequence?
<p>I'm using Java code (JPA with Hibernate 4.1) to insert into an Oracle 12c database.</p>

<p>Table : Dept :</p>

<pre><code>Name   Null     Type         
------ -------- ------------ 
DEPTNO NOT NULL NUMBER(4)    
DNAME           VARCHAR2(14) 
LOC             VARCHAR2(13)
</code></pre>

<p>From Java code, I am inserting value for <code>DNAME</code> and <code>LOC</code> as 'Research','London'.</p>

<p>Entity class :</p>

<pre><code>    @Entity(name="Department")
@Table(name="mydept")
public class Department {
    @Id 
    @SequenceGenerator(name = "MYDEPT_SEQ", sequenceName ="MYDEPT_SEQ") 
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MYDEPT_SEQ")
    @Column(name="deptno")
    private int id;
    @Column(name="dname")
    private String name;
    @Column(name="loc")
    private String location;
</code></pre>

<p>Sequence :</p>

<pre><code>CREATE SEQUENCE  "SCOTT"."MYDEPT_SEQ"  MINVALUE 30 MAXVALUE 9999999999999999999999999999 
INCREMENT BY 10 START WITH 80 NOCACHE  NOORDER  NOCYCLE  NOPARTITION ;
</code></pre>

<p>But while inserting, <code>deptId</code> is being inserted with values -20, 0, 10.</p>