I have to generate a custom Auto Increment Which reset every day at time 00:00 to date prefixed auto increment value
for example Jan 9, 2016, the id should be in range 1601090001 to 1601099999, and Dec 15, 2016 t should be like 1612150001 to 1612159999.
Eg: Characteristics of 1612150001 are as below
- The id is an INT
- first two digit represent the year, 16 means 2016
- digits 3 and 4 denotes month,
- 5 and 6 represents date
- and remaining just a counter, so I expect we have less than 9999 records generated in a day.
How can I achieve this in JPA, what is the best way, currently i did it using another table to count the current value and using the last updated time and current time to compute the prefix and to decide the auto increment part to reset to 1 or not. Which i feel not a right solution.
IS there a way I can use @GeneratedValue annotation with a custom strategy to this, if so how can I do without causing an error, where it fails to generate an ID.