File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate 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" Watch "Hibernate" New topic


P Arunkumar
Ranch Hand

Joined: Jan 05, 2012
Posts: 119

I am working on payroll project in java, struts2, spring and hibernate.

I need to generate employee-id automatically it can be numerical or alphanumerical, while iam saveing employee information in database the id wants to generate automatically and iam viewing employee information the with the employee-id the details wants to show . It can be possible or not please Guide me.

I am using SQL server 2008 database with hibernate mapping please give me some guide or some related website to solve my problem.

Please guide me.

Thanks in advance.
Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3902

Hibernate supports auto generation of keys for non-floating numbers (int, long etc..). But if you need keys with alphanumeric then you might need to implement your own logic for generating them and assign the one just before you persist the entity.

[How to ask questions] [Twitter]
Bogdan Baraila
Ranch Hand

Joined: May 23, 2011
Posts: 43
Checkout the hibernate id generator class. For example if you use generator class: identity - hibernate will initiate automatically the id with a generated value by the database table identity column. Or you can use sequence and the id will be initiated with a sequence that you need to create in the database (named hibernate_sequence) etc. You can check the hibernate documentation for more details.
I agree. Here's the link:
subject: Hibernate
It's not a secret anymore!