java persistence: sequence generator not working in expected way.
Hi,
I just played around with java persistence api and found that sequence generator annotations for making new primary key value not working correctly in my code. following is part of my code related to this problem.
in entity class:
... ...
@SequenceGenerator(name="mySeq", sequenceName="MY_SEQ_IN_DB")
@Id
@GeneratedValue(strategy=SEQUENCE, generator="mySeq")
@Column(name = "UPLOAD_ID", nullable = false)
private Integer uploadId;
... ...
I have a sequence called MY_SEQ_IN_DB in my oracle 9i testing db. When I ran the code to save a new entity instance to database I found that the new upload id is not the one that should be created from the MY_SEQ_IN_DB sequence, while the sequence was not increased either. It's instead something starting from 97 (in my pc), and increased just like a sequence, but every time I reran my code the sequence restarted itself again beginning with 97(of course the insert failed with primary key conflict). the behavior just looks like it's a sequence created and managed totally by the persistence api or toplink itself (I guess).
So, my question is, is this a designed behavior or have I done something wrong to make it not using the correct sequence in the db?
I used hibernate before, and assigning new primary key from sequence in this way works fine.
Thanks
JC.L