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

Hibernate primary Key/User defined Generator class

Rajkumar Kathiresan
Greenhorn

Joined: Dec 30, 2008
Posts: 8
Hi It may be a basic question.. but I am unable to find any answer for this..
I have a table Employee which have a column Emp_id,Emp_name and salary where Emp_id is primary key.
My Problem is My Emp_id should be like <CompanyName><SequenceNo> (eg. 'JAVA1','JAVA2','JAVA3') like this.
How to create this sequence?

Thanks & Regards,
Raj
Rajkumar Kathiresan
Greenhorn

Joined: Dec 30, 2008
Posts: 8
After a day Night spent over this problem I found solution for this
I give my own generator class NextSequence which implements the org.hibernate.id.IdentifierGenerator


my NextSequence class looks like


Now I have two problem

  • It bring value "Java9" as max value even i have a value "Java10". Is it any possible way to get the value "Java10" as max value
  • Its still specific to one Entity. It is possible to make it generalized one, where i can use this NextSequence class for all my tables.
    Like For Author my id would be like "Au001","Au002", etc.
    Help me on this.
    Thankx in advance
    Raja
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Hibernate primary Key/User defined Generator class
     
    Similar Threads
    problem in request.getparameter
    one to many mapping
    primary key class of entity beans?
    cascade-delete doesn't work
    Firing of Character method of Defualt Handler