Skip to content

Difference between generating UUID in Java and MySQL

I need to insert random id into one table and add that id to another table as foreign key. So I am not sure how to save UUID() if I generated it in MySQL but if I generate it in Java I can just save it into a variable. I wonder are there any drawbacks if I generate it in Java?




The point of UUIDs is that it doesn’t matter who generates them and there is no state you need to worry about (i.e. the chance that 2 separate systems both generating random UUIDs happen to generate identical UUIDs, rounds down to zero). Hence, let MySQL generate it. Or let java generate it. Whatever is more convenient. There is no inherent drawback to either form.

User contributions licensed under: CC BY-SA
7 People found this is helpful