-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: how do you generate non-sequence unique ids in hiberanate
PostPosted: Mon Nov 07, 2005 6:08 pm 
Newbie

Joined: Thu Jun 16, 2005 7:24 pm
Posts: 6
Is there a way to generate non-sequence unique IDs in hibernate? The ids getting inserted into database cannot be generatred in sequence.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 6:26 pm 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
Use a UUID generator:

Code:
<generator class="uuid"/>


But why are you wanting to do this? If you want to make IDs visible to the user (through a web page) but don't want the user to know sequence numbers, you'll need to use some form of "encryption". It could be something very basic, but that's the right way. If this is what you are trying to do, use a native or increment generator and then encrypt / scramble it in some reasonable way.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 6:41 pm 
Newbie

Joined: Thu Jun 16, 2005 7:24 pm
Posts: 6
Thanks SleepyBear, that makes sense but unfortunately that is not good enough for them.

The ids have be integer. Is there another way?


Top
 Profile  
 
 Post subject: Maybe hashCode()?
PostPosted: Mon Nov 07, 2005 7:08 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You can write your own generator. How about one that just returns the hashCode() of your business key? E.g. if all the objects in your table have a unique serial number, just return the hashCode of the serial number of the object from the generator. It will be sensible, useful, (probably) unique, and non-sequential.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 7:14 pm 
Beginner
Beginner

Joined: Sat Oct 22, 2005 11:16 pm
Posts: 40
lordofmordor wrote:
Thanks SleepyBear, that makes sense but unfortunately that is not good enough for them.

The ids have be integer. Is there another way?


Yes, you could use a plain old integer as a sequence number and then transform it into your non-sequential number. If you could explain how you're going to use this I could explain it in a way that makes more sense.

Basically, you could do something like multiply the sequantial integer with a large prime number to get a result that is "scrambled". You can also use modular exponentiation to essentially encrypt the integer.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.