You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Bobby Lawrence <ro...@jlab.org> on 2005/04/20 20:32:52 UTC

Oracle sequences...

Why is it that when using the SequenceManagerNextValImpl, my sequence 
numbers are not consecutive?
I see 2, 4, 6, 8...
instead of 2, 3, 4, 5, ...?

-- 
----------------------------
Bobby Lawrence
MIS Application Developer

Jefferson Lab (www.jlab.org)

 Email: robertl@jlab.org
Office: (757) 269-5818
 Pager: (757) 584-5818
----------------------------





---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Oracle sequences...

Posted by Martin Kalén <mk...@apache.org>.
Bobby Lawrence wrote:
> It seems that my database has triggers on it that insert the nextval 
> from the sequence upon insert.
> So OJB determines the sequence, and then Oracle does the same thing.
> Thats why my sequences are being called twice...

Also beware of Oracle sequence caching if your Oracle-server is sometimes
shut down between application runs. (Ie not an issue in production environements,
primarily if you are developing with a local Oracle instance.)

A default Oracle sequence without any caching flags will grab ~20 numbers
at a time and cache them in Oracle kernel for better performance.
(Not unlike OJB hi/lo SequenceManager, but with the crucial difference that
this in-memory cache survives client-side JVM shutdown.)

To avoid this even when using a server that shuts down frequently, you can
(at the expense of some Oracle kernel I/O-cycles) use the following SQL
to create the sequence:

  CREATE SEQUENCE seq_name START WITH initial_value NOCACHE;

Regards,
  Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Oracle sequences...

Posted by Bobby Lawrence <ro...@jlab.org>.
Crap - Nevermind -
It seems that my database has triggers on it that insert the nextval 
from the sequence upon insert.
So OJB determines the sequence, and then Oracle does the same thing.
Thats why my sequences are being called twice...
--Bobby

Armin Waibel wrote:

> Hi Bobby,
>
> Bobby Lawrence wrote:
>
>> Why is it that when using the SequenceManagerNextValImpl, my sequence 
>> numbers are not consecutive?
>> I see 2, 4, 6, 8...
>> instead of 2, 3, 4, 5, ...?
>>
>
> OJB obtain the sequence key before the object was inserted. If you do 
> an rollback the keys are lost. Further on the sequence base upon the 
> top-level class, e.g. if you declare an interface Animal with "extent" 
> classes Dog and Cat, the sequence will be used by Dog and Cat.
>
> regards,
> Armin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>

-- 
----------------------------
Bobby Lawrence
MIS Application Developer

Jefferson Lab (www.jlab.org)

 Email: robertl@jlab.org
Office: (757) 269-5818
 Pager: (757) 584-5818
----------------------------





---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: Oracle sequences...

Posted by Armin Waibel <ar...@apache.org>.
Hi Bobby,

Bobby Lawrence wrote:
> Why is it that when using the SequenceManagerNextValImpl, my sequence 
> numbers are not consecutive?
> I see 2, 4, 6, 8...
> instead of 2, 3, 4, 5, ...?
> 

OJB obtain the sequence key before the object was inserted. If you do an 
rollback the keys are lost. Further on the sequence base upon the 
top-level class, e.g. if you declare an interface Animal with "extent" 
classes Dog and Cat, the sequence will be used by Dog and Cat.

regards,
Armin

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org