• 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

Number Generation

 
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
As we are aware of Sequence Id Generation in Hibernate,How do we generate a custom sequence id number such that it increments for a count of 3.i.e
Sequence ---0,3,6,9,....multiples of 3. How do i achieve this in Hibernate.

Thanks and Regards
Deepak Lal
 
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
Writing your own custom generator will do this. However, I'd always warn against creating primary keys with any business meaning, since that business meaning is always likely to change.
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how should i write a custom generator for ID in Hibernate .please provide me some Sample code/inputs/links.Code Suggestions proovided will be helpful to proceed further.
 
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 just need to write a class that implements org.hibernate.id.IdentifierGenerator - there's not much to it. As for code suggestions, remember Hibernate is open source.
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,
If you could help me with the SAMPLE CODE for the same,It will be appreciated.I do not know how to proceed since im new to hibernate.Please need your help Paul.


Regards
Deepak Lal
 
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
What have you written so far? Remember JavaRanch is NotACodeMill. And remember, as I said before, Hibernate is open source and will contain a wealth of examples. Writing a generator is fairly simple, there is only one method to implement and you can implement it however you like.
reply
    Bookmark Topic Watch Topic
  • New Topic