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

Ask Your Question
0

generate a custom UID without using

Hello,

I would like to generate my own UID but I don't want to use Entry. Does it possible?

I ask you this because of this link: http://www.gigaspaces.com/wiki/displa...

I want to define a primary key for a POJO in order to avoid getting duplicate primary key. Does it realizable with Gigaspaces?

Thanks,

Carole

Edited by: carole benazza on Jun 26, 2008 7:25 AM

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=2414]{quote}

asked 2008-06-26 04:00:39 -0500

cbe gravatar image

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

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

See this thread: /[/question/5990/best-practice-for-unique-id-generation/?answer=5992#post-id-5992]&#8158 Shay

answered 2008-06-26 09:27:49 -0500

shay hassidim gravatar image
edit flag offensive delete link more

Comments

I use gs.xml and I did set: <id name="tradeId" auto-generate="true"/>

But, when I insert two objects with the same id in my space, the both objects did insert.

My goal is not to get several objects with some duplicate keys (like sql with primary key; indeed in sql we can't insert some objects with the same pk).

Besides, when I use annotation (@SpaceId), it's the same behaviour.

Carole

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

cbe gravatar imagecbe ( 2008-06-26 10:13:20 -0500 )edit

When you use auto-generate="true" as part of the gs.xml , GigaSpaces ignores your ID value placed into the field and generates one automatically.
If you want your ID value to be used as the bases for the Object UID you should use auto-generate="false".

By default , a second write for an object that has another object with the same ID within the space would cause an update operation within the space. You will not end up with 2 objects with the same ID within the space. If you would like the system to throw EntryAlreadyInSpaceException when you try to perform a second write with an existing ID you should use the com.jspaces.core.client.UpdateModifiers.WRITEONLY modifier with your write operation.

To use the auto-generate="false" with the @SpaceId you should have it annotated using the following:
@SpaceId (autoGenerate=false)

See more here:
http://www.gigaspaces.com/wiki/display/OLH/JavaSpacesPOJO

Shay

shay hassidim gravatar imageshay hassidim ( 2008-06-26 11:30:24 -0500 )edit

Shay,

I don't understand one thing. When I write in the space like: LeaseContext ret = space.write(trade ,null, /lease/ 0 ,/timeout/ 1000 , UpdateModifiers.WRITE_ONLY);

I can't throw EntryAlreadyInSpaceException. When I insert this corresponding catch clause, it's not allowed.

* Just one question which package comes from the method write in this example => [ http://www.gigaspaces.com/wiki/displa... ] "LeaseContext ret = space.write(employee ,/ lease/ 0 ,/timeout*/ 1000 , UpdateModifiers.WRITE_ONLY);"

Indeed, when I write the same line ("LeaseContext ret = space.write(employee ,/lease/ 0 ,/timeout/ 1000 , UpdateModifiers.WRITE_ONLY);") in my java code, I have an error because the method write(,,,,) doesn't exist: "The method write(Entry, Transaction, long) in the type JavaSpace is not applicable for the arguments (Trade, int, int, int)"

Therefore, I did add null argument to argt Transaction. So, I have: LeaseContext ret = space.write(trade ,null, /lease/ 0 ,/timeout/ 1000 , UpdateModifiers.WRITE_ONLY); And with this line, I have nothing which appears.

Carole

cbe gravatar imagecbe ( 2008-06-27 07:18:02 -0500 )edit

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

Stats

Asked: 2008-06-26 04:00:39 -0500

Seen: 64 times

Last updated: Jun 26 '08