-->
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: hibernate oracle sequence produces large gap
PostPosted: Thu Mar 17, 2011 6:10 pm 
Newbie

Joined: Wed Dec 01, 2010 1:25 pm
Posts: 2
Hi All,
I am using hibernate 3 , oracle 10g. I have a table: subject. The definition is here

Code:
CREATE TABLE SUBJECT
    (
     SUBJECT_ID NUMBER (10),
     FNAME VARCHAR2(30)  not null,
     LNAME VARCHAR2(30)  not null,
     EMAILADR VARCHAR2 (40),
     BIRTHDT  DATE       not null,
     constraint pk_sub primary key(subject_id) USING INDEX TABLESPACE data_index
    )
;


when insert a new subject, sub_seq is used to create an subject id, the definition is here
Code:
create sequence sub_seq
       MINVALUE 1
       MAXVALUE 999999999999999999999999999
       START WITH 1
       INCREMENT BY 1
       CACHE 100
       NOCYCLE ;



the Subject class is like this:
Code:
@Entity
@Table(name="ktbs.syn_subject")
public class Subject {

   @Id
   @Column(name="subject_id")
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SUB_SEQ")
    @SequenceGenerator(name="SUB_SEQ", sequenceName = "SUB_SEQ")
   private long subjectId;
   private String fname;
   private String lname;
   private String emailadr;
   private Date birthdt;
}


in the subject table , there have been 4555 subjects in the database loaded by plsql scripts from excel and the sub_sequence worked fine. subject ids range from 1--4555.

however, when i added a subject from my application using hibernate,
the sequence number jumped to 255050. After several days running, the subject ids generated by hibernate look like this

270079
270078
270077
270076
270075
270074
270073
270072
270071
270070
270069
270068
270067
270066
270065
270064
270063
270062
270061
270060
270059
270058
270057
270056
270055
270054
270053
270052
270051
270050
265057

265056
265055
265054
265053
265052
265051
265050
260059
260058
260057
260056
260055
260054
260053
260052
260051
260050
255067

255066
255065
255064
255063
255062
255061
255060
255059
255058
255057
255056
255055
255054
255053
255052
255051
255050
4555

4554
4553
.
.
.
.
1


There are several large gaps: 4555 to 255051, 255067 to 260051, 265057 to 270051

this is a waste and not a desired behavior.

does anyone know why this happens and hot to fix it

Thanks


Top
 Profile  
 
 Post subject: Re: hibernate oracle sequence produces large gap
PostPosted: Wed Jul 27, 2011 3:29 am 
Newbie

Joined: Tue Feb 06, 2007 11:59 am
Posts: 4
A sequence is not guaranteed to be consecutive.

Anyway you can improve your results leaving your sequence cache in 1.


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.