views:

189

answers:

1

I have the following problem. I assign to any object in my database a UUID. When I get a UUID from any source, to obtain the object I need to know what type of object is, so I can query the correct table in the database. As far as I understand, UUID version 5 supports namespacing, but I am not sure I clearly understand its meaning.

Is it possible to associate to a UUID information about the namespace it belongs, so to recover it later ?

+1  A: 

Is it possible to associate to a UUID information about the namespace it belongs,

Yes, see this document.

so to recover it later

Maybe. The problem is that two different namespaces may map to the same hash value. To avoid this, you should manually number your names (instead of hashing them). Then put the number into the octets 0-3. That gives you a deterministic mapping between UUIDs and names.

Aaron Digulla
I guess that this is not automatic with uuid5. you have to implement the uuid standard for this to happen. or not ?
Stefano Borini
That's simple: Use a generator which can create version 5 UUIDs and just overwrite the first four octets before you hand the UUID to the DB.
Aaron Digulla