I need to create unique numbers for objects inserted in a table. Each number consists of the date the object was created and the serial number: date + sn. Serial numbers should be reset early next day.
| id | creation date | unique number |
--------------------------------------
| 1 | Sep 1, 2010 | 201009011 |
| 2 | Sep 1, 2010 | 201009012 |
| 3 | Sep 2, 2010 | 201009021 |
| 4 | Sep 2, 2010 | 201009022 |
How to do this using JPA over Hibernate (they are currently used for all interactions with the database) and a safe transaction method (entities can be inserted at the same time) in the MySQL database?
Of course, I would appreciate a description of all the other approaches. Thank.
source
share