When you use for the first time you get the number 1, but it should return 0.
When you use for the second time you get the number 1, andit should return 1.
So when i try to show beforehand the next number for the first document i use getCurrentValue() + 1 and it returns 2 (error).
But for the second document, the same formula returns 2 (ok)
I tried to use setStartValue(0) but again a get a number 2 as answer.
I think the logic should be changed. Thanks in advance for your help.
I can’t use createNextValue() because it will create a new value and i need to show beforehand the next value, but if the document is canceled the code should not increment. If i use createNextValue(), the value increments even if the document is canceled.
Unfortunately, we cannot guarantee the correct behavior of getCurrentValue() for your case, it’s even stated in the Javadocs:
/**
* Returns the current value of the sequence. For some implementations
* {@link #createNextValue(Sequence)} must be called at least once beforehand.
*
* @param sequence object {@link Sequence}
* @return current value
*/
long getCurrentValue(Sequence sequence);
So the getCurrentValue method should be used only for information purpose, for example to show the last returned value in an administrative UI.
Perhaps you need to develop your own counting mechanism based on a regular table.