title: How to use Postgres sequence with JPA?
body: <p>I have a 'customer' table in my postgresql database with a particular field: <code>cus_number</code> which has a sequence defined. This field is not the primary key, there's already an <code>cus_id</code> field.</p>
  
  <p>The default value of the cus_number is </p>
  
  <pre><code>nextval('customer_cus_number_seq'::regclass) it's the sequence.
  </code></pre>
  
  <p>With pgadmin, when I insert a row in this customer table with a null value as the <code>cus_number</code> it works fine and the default value sequence is used.
  But in my webap, when I persist a new Customer(), the row inserted has nothing in the field <code>cus_number</code>.</p>
  
  <p>Here is my custom entity definition : </p>
  
  <pre><code>public class Customer implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @Column(name = "pers_id")
  private Integer id;
  
  ...
  
  @Column(name = "cus_number")
  private Integer number;
  
  ...
  </code></pre>
  
  <p>}</p>
  
  <p>And the sequence script : </p>
  
  <pre><code>  CREATE SEQUENCE customer_cus_number_seq
    INCREMENT 1
    MINVALUE 100
    MAXVALUE 9223372036854775807
    START 114
    CACHE 1;
  </code></pre>
  
  <p>ALTER TABLE customer_cus_number_seq
    OWNER TO fizzconsulting;</p>
  
  <p>Do you some tips for me please ?</p>
  
  <p>Thanks.</p>