Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question

Best practice for unique ID generation

In a database centered design, it's very easy to get a unique identifier(primary key) by using database provider's built-in sequence. But it's not the case in Gigaspaces. I'm wondering if there is any best practice for unique ID generation in Gigaspaces. I'm thinking of getting the ID from a database sequence table and then passing it onto Gigapaces. But I'd like to know if there is any better implementation.




  1. UUIDBean.java

This thread was imported from the previous forum.
For your reference, the original is available here

asked 2008-05-21 12:58:12 -0600

noiseba gravatar image

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted

if the Space UID generator is not good enough for you and you need different one you can try this:

net.jini.id.Uuid uid1 = UuidFactory.generate();

I'm not sure what is the cost of this UID generator compared to a database one.
I managed to create 1 million UIDs in 7 seconds.


answered 2008-05-21 17:10:10 -0600

shay hassidim gravatar image
edit flag offensive delete link more

Back in my EJB days this issue came up often.

There are several patterns that address different variants of this need. For complete pattern info, you can look at chapter 5 of the following EJB design patterns book (as a PDF) http://labs.cs.utt.ro/labs/sprc/html/...

When a non-sequenced String PK is needed you can use the attached UUIDBean. Feel free to improve it.


Owen. h4. Attachments


answered 2008-05-22 10:27:57 -0600

owentaylor gravatar image
edit flag offensive delete link more

There's the UUID class, part of the JDK since Java 1.5, that may fit your need.


answered 2008-05-22 10:35:19 -0600

vanio gravatar image
edit flag offensive delete link more


Sorry, I do a mistake. Oups!!


Edited by: carole benazza on Jun 26, 2008 10:12 AM

Edited by: carole benazza on Jun 26, 2008 10:13 AM

cbe gravatar imagecbe ( 2008-06-26 10:04:27 -0600 )edit

Hi Simon,

The answer depends on the requirements you have for id. If all you need is a unique identifier, than take a look at the @SpaceId with auto generation equals to true. This annotation makes sure the identifier is generated by the space.

As a side note; in a distributed system, trying to centralize services, like id generation usually works against scalability requirements.


answered 2008-05-21 13:05:49 -0600

nirpaz gravatar image
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2008-05-21 12:58:12 -0600

Seen: 709 times

Last updated: May 22 '08