0

How to apply auto increment of customize ID in Grails 3 like-

STD_ID
-----------
REG-17-0001
REG-17-0002
REG-17-0003
APC
  • 144,005
  • 19
  • 170
  • 281
Syed Sarek
  • 373
  • 2
  • 12
  • Is the prefix always going to be REG-17- ? – Mike W May 08 '17 at 11:54
  • 'REG' is My default Prefix and '17' is the last 2 digit of current year. – Syed Sarek May 08 '17 at 12:10
  • Have a look at http://stackoverflow.com/questions/4259746/whats-the-best-way-to-define-custom-id-generation-as-default-in-grails – Prakash Thete May 08 '17 at 14:09
  • Possible duplicate of [What's the best way to define custom id generation as default in Grails?](http://stackoverflow.com/questions/4259746/whats-the-best-way-to-define-custom-id-generation-as-default-in-grails) – Strelok May 08 '17 at 14:18
  • I followed this one but doesn't work. My process is different where ID will increase as 4 digit of integer and remaining string will same. – Syed Sarek May 11 '17 at 04:57

1 Answers1

0

You can customize the generator in your mapping closure:

static mapping = {
    id generator: 'hilo'...
}

See the documentation1, documentation2.

Anton Hlinisty
  • 1,441
  • 1
  • 20
  • 35
  • This is Hibernate’s built in hilo generators which uses a separate table to generate ids. But I want to generate this STD_ID with ID column on same table. – Syed Sarek May 08 '17 at 12:06