# Customize Sequence ID Generation

**URL:** <https://discourse.hibernate.org/t/customize-sequence-id-generation/10463>\
**Category:** Hibernate ORM\
**Created:** [October 16, 2024, 7:52pm UTC](https://discourse.hibernate.org/t/customize-sequence-id-generation/10463 "2024-10-16T19:52:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![evergreen](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@evergreen](https://discourse.hibernate.org/u/evergreen)\
**Post date:** [October 16, 2024, 7:52pm UTC](https://discourse.hibernate.org/t/customize-sequence-id-generation/10463/1 "2024-10-16T19:52:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [October 17, 2024, 3:03pm UTC](https://discourse.hibernate.org/t/customize-sequence-id-generation/10463/2 "2024-10-17T15:03:02Z")

</div>

The [Hibernate ORM documentation](https://docs.jboss.org/hibernate/orm/6.6/userguide/html_single/Hibernate_User_Guide.html#identifiers-generators-IdGeneratorType) has an example of a custom sequence generator. Take a look at the [full source code](https://github.com/hibernate/hibernate-orm/blob/6.6/hibernate-core/src/test/java/org/hibernate/orm/test/id/custom/CustomSequenceGenerator.java) which will hopefully help you figure this out.
