-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: to populate an Id column using @Generatedvalue annotation
PostPosted: Thu Mar 01, 2012 2:39 am 
Newbie

Joined: Thu Mar 01, 2012 2:14 am
Posts: 1
Hi,

I am new to Hibernate , I have developed an application using Hibernate with Annotations

I am trying to populate ID column using @GeneratedValue(strategy=GenerationType.IDENTITY) its working fine for the single session but when i starts a new session the sequence is not in a continuous fashion

i.e; for the first run i have inserted 10 values and it populates 1 to 8 for those 8 columns and when i start the next session and tries to insert another 2 rows it is populating as 81 and 82 rather 9 and 10

I have tried with all the defaults available with that GenerationType .

How could i overcome this

please help me out


Thanks in advance


Top
 Profile  
 
 Post subject: Re: to populate an Id column using @Generatedvalue annotation
PostPosted: Mon Mar 05, 2012 3:34 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
sequence is not in a continuous fashion


With strategy=GenerationType.IDENTITY you could have sequence in a continuous fashion,
if your database would support 'identity columns' like for example DB2, MySQL, MSSQL, Sybas, HSQLDB are doing.
Apparently your database does not and so hibernate uses a sequence or hilo for generating identifiers.
With this implementations it is normal that there will be gaps in the ID's sequence as you describe.
It is because each HibernateSessionFactory is allocating a entire ranges of numbers, in order to avoid to frequent accesses to the sequence.
But this number gaps are absolutely no problem, the number range is big enough and will not run out of numbers.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.