• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Problem in generating the Primary Key using a Sequence

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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: 17344
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 .
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!