Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auto-generating unique Strings with limited length in Hibernate

 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
I am finding a way to automatically create usernames in a table with a username as a primary key. I tried to use UUID to auto-generate Strings, but I can't find a way to limit the length of the generated string to be 8. By default, it generates Strings with the length of 32.

So if there is anyone who can help with this problem, please help me...

Thanks!
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate says that you can make your own generator; there is an IdentifierGenerator interface for this.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your reply, Edvins! It seems like I need to use the DBMS' native function to get an upcoming unique string in a specific length.

Anyway, thank you for shedding some light on it...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ko Ko, long time no see. How are things going?

Mark
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Things are going ok for me. Yourself?

It's been a while. I have been busy with my master thesis. It's done now!

Ko Ko
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic