Harsh Patel
Harsh Patel

Reputation: 11

How to autogenerate ids Using annotations in Hibernate?

I want to create table of product in which i can save product id as primary key , and second table there is category table in this table there is the catid as primary key,but problem is both Generate Key In Fashion of 1,2,3,4 mans both have Same column ,How to generate key likes PID001,PI002..... and CATID001 ,CATID002

Upvotes: 1

Views: 95

Answers (1)

Bhushan Uniyal
Bhushan Uniyal

Reputation: 5703

In this case you should use custom id generator strategy.

For Custom Id generation we need to implement IdentifierGenerator interface and need to provide the body of generate method.

IdentifierGenerator have method generate so you need to provide the body of it.

Here is an example of custom id generator strategy.

Upvotes: 2

Related Questions