You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Baskar Sikkayan <te...@gmail.com> on 2013/01/03 11:00:58 UTC

UUID - Java

Hi,
  I use the following code to generate the primary key.

public static java.util.UUID getTimeUUID() {

        return java.util.UUID.fromString(new
com.eaio.uuid.UUID().toString());

    }

Is this the correct approach?

Do let me know if there i any better approach which guarantees no conflicts.

Thanks,
Baskar.S

Re: UUID - Java

Posted by aaron morton <aa...@thelastpickle.com>.
There are several classes of UUID, so it depends a little on what the call to com.eaio.uuid.UUID() is doing. In general you will be ok.

In general you can assume it's unique, however version 1 time UUID's may not be. As they contain a time component and the machine mac address, which is sometimes zero'd out so you can reproduce a UUID for a specific time. See http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28MAC_address.29 and http://wiki.apache.org/cassandra/FAQ#working_with_timeuuid_in_java

 Hope that helps. 

-----------------
Aaron Morton
Freelance Cassandra Developer
New Zealand

@aaronmorton
http://www.thelastpickle.com

On 4/01/2013, at 2:26 AM, "Hiller, Dean" <De...@nrel.gov> wrote:

> Another option is PlayOrm UniqueKeyGenerator.generateKey().  While it is not returning a UUID, it does return a unique key for a specific cluster that is nice and short too.
> 
> Dean
> 
> From: Baskar Sikkayan <te...@gmail.com>>
> Reply-To: "user@cassandra.apache.org<ma...@cassandra.apache.org>" <us...@cassandra.apache.org>>
> Date: Thursday, January 3, 2013 3:00 AM
> To: "user@cassandra.apache.org<ma...@cassandra.apache.org>" <us...@cassandra.apache.org>>
> Subject: UUID - Java
> 
> Hi,
>  I use the following code to generate the primary key.
> 
> public static java.util.UUID getTimeUUID() {
> 
>        return java.util.UUID.fromString(new com.eaio.uuid.UUID().toString());
> 
>    }
> 
> Is this the correct approach?
> 
> Do let me know if there i any better approach which guarantees no conflicts.
> 
> Thanks,
> Baskar.S


Re: UUID - Java

Posted by "Hiller, Dean" <De...@nrel.gov>.
Another option is PlayOrm UniqueKeyGenerator.generateKey().  While it is not returning a UUID, it does return a unique key for a specific cluster that is nice and short too.

Dean

From: Baskar Sikkayan <te...@gmail.com>>
Reply-To: "user@cassandra.apache.org<ma...@cassandra.apache.org>" <us...@cassandra.apache.org>>
Date: Thursday, January 3, 2013 3:00 AM
To: "user@cassandra.apache.org<ma...@cassandra.apache.org>" <us...@cassandra.apache.org>>
Subject: UUID - Java

Hi,
  I use the following code to generate the primary key.

public static java.util.UUID getTimeUUID() {

        return java.util.UUID.fromString(new com.eaio.uuid.UUID().toString());

    }

Is this the correct approach?

Do let me know if there i any better approach which guarantees no conflicts.

Thanks,
Baskar.S