This might sound funny by db_nextval has given me the same value twice on our system resulting in commit errors, therefore I put some extra precautions into the code. Hopefully it will not be necessary in the future as it fixes the symptoms and not the roots, but for the time being it is the best we got