0

I have a different product made from differents places. I need to create a custom key.

Product String id String name String description String source ...

Id is a String with this format and the counter must be reseted every year year-codsource-0000001 eg.

next year PT00A-00001 US00A-00001

I tried using @Tablegenerator and created a table CONTROL_IDS

PREFIX COUNTER
PT00A 1
US00A 4

@TableGenerator(name = "idgen",table = "CONTROL_IDS",pkColumnName = "PREFIX",valueColumnName = "COUNTER",pkColumnValue = "PT00A", allocationSize=1)

Or even can select the prefix dinamically

@TableGenerator(name = "idgen", table = "CONTROL_IDS", pkColumnName = "PREFIX", valueColumnName = "COUNTER", pkColumnValue = "{prefixname}", allocationSize=1)

Thank you for any guide

I tried using @TableGenerator and @GenericGenerator and making a class to create prefixed value to the counter or exits other kind of generators?

Thank you for any guide.

  • See https://stackoverflow.com/questions/55587520/is-there-a-way-to-create-string-sequence-using-generatedvalue-with-prefix/55588963#55588963 – Christian Beikov Nov 30 '22 at 04:53
  • Does this answer your question? [Is there a way to create String sequence using @GeneratedValue with prefix?](https://stackoverflow.com/questions/55587520/is-there-a-way-to-create-string-sequence-using-generatedvalue-with-prefix) – Christian Beikov Nov 30 '22 at 04:53

0 Answers0