• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Problem in generating the Primary Key using a Sequence

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All ,
I am trying to persist an object and also generating the primary key using a default sequence . But the problem is that the Primary key is getting incremented by 2 instead of 1 . My code looks like this :
----------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------

Please provide me with some pointer as to know where the things are going wrong.
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is your class mapping look like. When you say the default sequence, do you mean something like "hibernate_seq" and then therefore more than one object is mapped to generating the PK from that sequence table, such that I insert one record in table A it gets id 1, then insert one record into table B it gets id 2, then insert again into table A and it gets id 3?

Or do you have it mapped for objects A mapped to Table A and Sequence "a_seq" and for Object B mapped to Table B and sequence "b_seq"

Mark
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A sequence in JPA maps to a database sequence. You should check your DB first.

select <seqname>.NEXTVAL FROM DUAL

if it gets incremented by 1, then check your code, later report a bug to the jpa vendor
 
Amit Chauhan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
By default sequence I mean that I have not created it using sql at the database rather I am creating it directly while code .

Here is the entity bean code :



*******The most strange thing is that I find the value of sequence being incremented by 2 and not by 1 .


Kindly help me out .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic