Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
931 views
in Technique[技术] by (71.8m points)

spring - Sequence's current value advances to next 100 upon reconnection in derby

I am having an issue with derby sequences with embedded database. When I first connect to the data base it gives me the correct sequence next value with the following statement.

VALUES (NEXT VALUE FOR :seqNm)

But when restart my desktop application, there by reconnecting to the database, the next value gives me the next hundredth value. It seems like derby uses some caching for preallocating the sequence numbers.

e.g. if my sequence starts with 100, First connection to the data base gives me sequences as 100, 101, 102 and so on.

Second connection to the data base gives me sequences as 200, 201, 202, 203 and so on.

Third connection to the data base gives me sequences as 300, 301, 302, 303 and so on.

Is there any workaround for this issue? I am using spring to connect to the database.

Thanks!!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to https://db.apache.org/derby/docs/10.9/ref/rrefproperpreallocator.html, yes there is a sequence preallocator:)

In configuration just enter:

derby.language.sequence.preallocator=number

where number is a prealocated number of sequences OR

derby.language.sequence.preallocator=className

where className leads to a class implementing SequencePreallocator if you want some more advanced sequence alocation...

Hope it helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...