• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate primary Key/User defined Generator class  RSS feed

 
Rajkumar Kathiresan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!