users@jersey.java.net

Re: [Jersey] best practice for generating unique id in the resources

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 03 Nov 2008 08:55:23 +0100

On Nov 1, 2008, at 4:18 AM, Jeff Schmidt wrote:

> Hi Arul:
>
> I think you want to do this:
>
> @POST
> @Consumes("application/xml")
> @Produces("application/xml")
> public Response addCustomer(Customer customer) {
> long customerId = 1234L; //Wherever this comes from (DB
> sequence, atomic counter etc.).

If one utilizes an incremental counter then it is possible to detect
if a resource was created then deleted and thus distinguish between
404 (Not Found) and 410 (Gone).

An alternative is to use a UUID. Java has support for type 4 UUIDs
(random ones) but this may result in collisions...

Paul.