persistence@glassfish.java.net

Re: initialValue doesn't work in sequence

From: Andrei Ilitchev <andrei.ilitchev_at_oracle.com>
Date: Fri, 7 Sep 2007 11:24:57 -0400

That may currently happen if your db is PostgreSQL - see https://glassfish.dev.java.net/issues/show_bug.cgi?id=3218.

Currently TopLink doesn't support BOTH sequence and identity on the same database platform.
PostgreSQLPlatform was implemented to support identity.

The workaround for now is to use custom PostgreSQLPlatformSupportingSequences platform described in my posting in https://glassfish.dev.java.net/issues/show_bug.cgi?id=3218: this resolves the usage of user-defined sequences,
but not sequence creation - for now you have to create sequences "by hand" in the database.

Thanks,

Andrei
  ----- Original Message -----
  From: Krzysztof Adamczyk
  To: persistence_at_glassfish.dev.java.net
  Sent: Friday, September 07, 2007 9:38 AM
  Subject: initialValue doesn't work in sequence


  Hi,

  I have the following problem:
  An entity has a primary key generated with a sequence.
  I need to have this sequence initialized to the value of 10000.
  The following code doesn't work. My sequence starts with 1 :(
  What's more, the sequenceName seems to have no effect.
  TopLink creates sequence with a different name.
  What am I doing wrong? Is this a bug?
  I will appreciate any help.


  @Entity
  @Table(name = "expense_contr_contractors")
  @SequenceGenerator(name = "expense_contractor_sequence", sequenceName =
  "contr_seq" , initialValue = 10000, allocationSize = 1)
  public class ExpenseContractor extends ModelObject implements Serializable {

   private long id;

   @Id
   @Column(name = "contr_id", nullable = false)
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "expense_contractor_sequence")
   public long getId() {
    return id;
   }

   public void setId(final long id) {
    this.id = id;
   }
  }


  Greetings,
  Chris