wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Number Generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Number Generation" Watch "Number Generation" New topic
Author

Number Generation

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

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


When The Going Gets Tougher,The Tougher gets Going
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Jul 01, 2008
Posts: 507

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

Joined: Apr 14, 2004
Posts: 10336

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Number Generation