One of the requirements of my billing software is that the invoice number must be sequential & continuous. (no invoice number can be skipped).
I tried setting the invoice number as PK, and tried hibernate's increment & native generator, but both of them do not guarantee continuous number when a transaction fails. The next invoice will have the next invoice number, which introduces a gap (not continuous).
What should I do?
Use invoiceID as PK, set invoiceNumber as a Nullable column, and set invoice number at postInsert() with a thread-safe number generator?