Reputation: 91840
I'd like to know how to create my own custom id generator for JPA. Instead of just having a generator which is a numeric incrementer, I'd like to create an alphanumeric, case-sensitive generator, akin to how URL shorteners keep track of sites.
For example, URL shorteners don't use numerical keys because they are inefficient in comparison to a case-sensitive alphanumeric generator. Essentially, something like urlshortener.com/20
could be shortened as urlshortener.com/t
. This difference becomes exponentially better as numbers increase, as it's 10^n vs 62^n where n is the number of digits available.
How can I implement this in JPA as a SequenceGenerator?
Upvotes: 0
Views: 370
Reputation: 1283
For storing in the database this is not more efficient. For display you can use Base64 or Base32 encoding.
Upvotes: 2