• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String as primary key in Hibernate

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I have table in the database (sqlserver) with varchar data type as primary key.

I want to know what to use as primary key generatec class in the tablename.hbm.xml file.

Like in case of numeric columns we use identity or hilo what will be an equivalent for String (varchar).

I tried using uuid.hex but that generates a huge id & my column size is only 16.

I have seen some thing like generated class - assigned. but never found any implementation example for the same

Do post your views


Bye
Hari
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
uuid.hex is the only generation strategy which returns a String. If you can't use this then for varchar primary keys your other options are is to use an assigned key, rather than a generated one, or to write your own IdentifierGenerator implementation.

However, if your PK is a relatively meaningless String (such as uuid.hex would generate) why not change its type to int or long and use one of the other generation modules?
[ May 13, 2005: Message edited by: Paul Sturrock ]
 
Hari patnaik
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul

Thanks for your prompt response.

Wish I could follow your suggestion. But i do not have the liberty to change the column type of the table as lot of other apps also use the database

I have a requirement of generating a alpha numeric data (unique values) for this column & the data type of the column is String.

I want some sort of generator class equivalent to the above which I can use in Hibernate xml to map

If you see a solution do post it


Bye
Hari
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome.

You'll need to decide how your generation algorithm is going to work, and write your own IdentifierGenerator implementation which uses it. Remember Hibernate is open source, so I'd suggest looking at how they implement the other IdentifierGenerators and see if they give you some ideas.
 
reply
    Bookmark Topic Watch Topic
  • New Topic