I think UUID.randomUUID() will always be cheaper than a DB roundtrip. Also 
bootique-metrics has an injectable and a fast semi-unique ID generator [1], 
which you can probably re-purpose. From [2]:

"TransactionIdGenerator [..] does not attempt to be truly random, or even fully 
unique (though the number of possible combinations is large enough, so this is 
not a practical concern). [..] the algorithm focuses on id generation speed 
instead of randomness or uniqueness."

Andrus


[1] 
https://github.com/bootique/bootique-metrics/blob/master/bootique-metrics/src/main/java/io/bootique/metrics/mdc/TransactionIdGenerator.java
[2] 
https://medium.com/@andrus_a/the-state-of-bootique-early-2018-part-2-aa6f163440f3


> On May 23, 2018, at 10:53 AM, Ken Anderson <[email protected]> wrote:
> 
> Is it a child of another object where the numbers would reset, or is it 
> unique throughout the DB?  If so, why isn’t it the primary key?
> 
>> On May 23, 2018, at 4:52 PM, Tony Giaccone <[email protected]> wrote:
>> 
>> Imagine I have a field in a persistent object, the field is not the primary
>> key, and I want it to be unique.  So the obvious choice to me is to use a
>> sequence value from the db, so that I can avoid trying to calculate a value
>> in java.
>> 
>> Is there an easy way to access that sequence value, from java, using
>> Cayenne?
>> 
>> 
>> Tony
> 

Reply via email to