0

I want to create a primary key of String type, which will be auto-generated by Spring JPA. I want that the primary key should start with "USER****" and it should be of uniform length. e.g. USER0012, USER0007, USER1409 etc. And also want each time next user id will get generate.

I am new to Spring JPA, I know we can generate long or int type of primary key with @GeneratedValue(strategy = GenerationType.IDENTITY) or @GeneratedValue(strategy = GenerationType.AUTO), but is there any inbuilt mechanism for this?

DEV_BOT
  • 33
  • 9
  • 1
    Hi, this might be helpful: https://stackoverflow.com/questions/37747218/how-to-implement-a-custom-string-sequence-identifier-generator-with-hibernate As far as I know you need a custom generator. – don Apr 02 '22 at 15:03

0 Answers0