-->
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.  [ 4 posts ] 
Author Message
 Post subject: sequence generator - How can I set the starting value
PostPosted: Wed Sep 22, 2004 9:22 am 
Newbie

Joined: Wed Sep 22, 2004 9:05 am
Posts: 2
Hibernate version: 2.6.1

Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true):
Hibernate: select specialty_id_seq.nextval from dual
Hibernate: insert into PORTAL_CLINICALGUID_SPECIALTY (name, specialty_id) values (?, ?)

I am getting an ORA-00001 unique constraint (xxxx) violated.

I know this is because the sequence is starting with a value of 1.

The table in question has been prepopulated with approximately 50 rows.

Here is the XDoclet used to define the generator:

/**
* @hibernate.id
* column = "specialty_id"
* generator-class = "sequence"
* unsaved-value = "-999"
* @hibernate.generator-param
* name="sequence"
* value="specialty_id_seq"
*/


Is there a way I can set the starting sequence value to say 100?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 9:38 am 
Newbie

Joined: Fri Aug 27, 2004 5:36 pm
Posts: 16
Location: Pittsburgh
you will need to reset the value at database level.

or exhaust some values from sequence by calling following several times.

select specialty_id_seq.nextval from dual


Top
 Profile  
 
 Post subject: Could be done using Oracle
PostPosted: Wed Sep 22, 2004 9:40 am 
Newbie

Joined: Mon Sep 20, 2004 10:27 am
Posts: 7
As you are using Sequence Generator of Oracle , you cannot configure Sequence Id in Hibernate, but you could setup your Sequence in oracle to start from 50.

Example
CREATE SEQUENCE employee_id_no START WITH 51 INCREMENT BY 1 MAXVALUE 9999;[/b]

_________________
Rgds,

--Siva Jagadeesan
Application Developer
ThoughtWorks, Inc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 10:05 am 
Newbie

Joined: Wed Sep 22, 2004 9:05 am
Posts: 2
I actually found the solution. It may break compatibility with other db's that use the "sequence" generator but here is all I had to do.

Original:
/**
* @hibernate.id
* column = "specialty_id"
* generator-class = "sequence"
* unsaved-value = "-999"
* @hibernate.generator-param
* name="sequence"
* value="specialty_id_seq"
*/

/**
* @hibernate.id
* column = "specialty_id"
* generator-class = "sequence"
* unsaved-value = "-999"
* @hibernate.generator-param
* name="sequence"
* value="specialty_id_seq"
* @hibernate.generator-param
* name="parameters"
* value="START WITH 100"
*/

Notice the addition of the second "generator-param" this allows parameters to passed directly to the DDL.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.