Customize Sequence ID Generation

Using Hibernate 6.5.3. I would like to generate customized, string based IDs for an entity.

I know I can use the @GeneratedValue and @SequenceGenerator annotations to obtain a sequence value from my SQL Server database, but my particular use case calls for formatting the number as string so I can pad zeros to it as well as set a prefix. The entity in question uses a varchar data type for the PK and has no default value or identity configured.

I have found several articles regarding string-based sequence generation but they all seem to be based on previous versions of Hibernate, and whenever I try to implement any of these strategies I encounter issues that prevent me from running the application at all.

Any suggestions?

The Hibernate ORM documentation has an example of a custom sequence generator. Take a look at the full source code which will hopefully help you figure this out.