Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Number Generation

 
Deepak Lal
Ranch Hand
Posts: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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: 561
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic