-1

I am trying to create a 8 digit unique number as the transaction id and increment it by one for other transaction.

for suppose the transaction id be for the first booking is 98723450

then after every booking should increment by one as 98723451,98723452 etc...

For this I am using Search Results Web results Spring Data JPA and hibernate.

Lemmy
  • 2,437
  • 1
  • 22
  • 30
arun
  • 1
  • 2
  • 2
    Welcome to Stackoverflow! Please take some time to read [How to ask good questions?](https://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Also please try to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of your own attempt and show it to us. – Smile Jan 13 '20 at 10:41
  • i hope you can get this now??? and i didn't give a try to show it to u.@Smile – arun Jan 13 '20 at 10:57

1 Answers1

0

You can use database sequence for that and configure it like following in Hibernate.

@Id
@SequenceGenerator(name = "mySeqGen", sequenceName = "mySeq", initialValue = 98723450, allocationSize = 100)
@GeneratedValue(generator = "mySeqGen")
private int myId;
Smile
  • 3,832
  • 3
  • 25
  • 39