# Hibernate 6 Migration - Id Generation

**URL:** <https://discourse.hibernate.org/t/hibernate-6-migration-id-generation/7556>\
**Category:** Hibernate ORM\
**Created:** [April 26, 2023, 11:52am UTC](https://discourse.hibernate.org/t/hibernate-6-migration-id-generation/7556 "2023-04-26T11:52:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hakan\_Kucuk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/hakan_kucuk/32/2394_2.png) [@Hakan\_Kucuk](https://discourse.hibernate.org/u/Hakan_Kucuk)\
**Post date:** [April 26, 2023, 11:52am UTC](https://discourse.hibernate.org/t/hibernate-6-migration-id-generation/7556/1 "2023-04-26T11:52:55Z")

</div>

have a base entity. I have a sequence per entity strategy. Increment size is 100. As per documentation in hibernate 6, default strategy is sequence per entity. But i couldn’t find a way to set default increment size to 100.

How i can migrate the code below to work with hibernate 6.

```auto

@Getter
@Setter
@MappedSuperclass
@Audited
public abstract class AbstractEntity {

    @Id
    @GeneratedValue(generator = "optimized-sequence")
    @GenericGenerator(
        name = "optimized-sequence",
        strategy = "enhanced-sequence",
        parameters = {
            @Parameter(name = SequenceStyleGenerator.CONFIG_PREFER_SEQUENCE_PER_ENTITY, value = "true"),
            @Parameter(name = SequenceStyleGenerator.INCREMENT_PARAM, value = "100")})
    private Long id;

```

---

<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:** [April 26, 2023, 12:34pm UTC](https://discourse.hibernate.org/t/hibernate-6-migration-id-generation/7556/2 "2023-04-26T12:34:29Z")

</div>

I don’t think there is a way to configure a global default increment size yet. Try replacing the `@GenericGenerator` with `@SequenceGenerator(name = "optimized-sequence", allocationSize = 100)`. If that doesn’t work, you can create a feature request for this if you want. In the meantime, you will have to define every sequence generator on the respective entity types by annotating e.g. `@SequenceGenerator(name = "optimized-sequence", sequenceName = "abc_seq", allocationSize = 100)`

---

<div class="post-metadata">

**Author:** ![Hakan\_Kucuk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/hakan_kucuk/32/2394_2.png) [@Hakan\_Kucuk](https://discourse.hibernate.org/u/Hakan_Kucuk)\
**Post date:** [April 26, 2023, 1:55pm UTC](https://discourse.hibernate.org/t/hibernate-6-migration-id-generation/7556/3 "2023-04-26T13:55:51Z")

</div>

It doesn’t work.

Since it is our base entity, i don’t want to move it from base to every entity. We have a lot of entities.

---

<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:** [April 26, 2023, 2:09pm UTC](https://discourse.hibernate.org/t/hibernate-6-migration-id-generation/7556/4 "2023-04-26T14:09:17Z")

</div>

Then there is no other way right now. Please create a JIRA issue for the feature request.

---

<div class="post-metadata">

**Author:** ![skparmar](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@skparmar](https://discourse.hibernate.org/u/skparmar)\
**Post date:** [April 29, 2025, 4:33am UTC](https://discourse.hibernate.org/t/hibernate-6-migration-id-generation/7556/5 "2025-04-29T04:33:09Z")

</div>

Is anything for this issue have been implemented?

---

<div class="post-metadata">

**Author:** ![puelo](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@puelo](https://discourse.hibernate.org/u/puelo)\
**Post date:** [May 6, 2026, 3:59pm UTC](https://discourse.hibernate.org/t/hibernate-6-migration-id-generation/7556/6 "2026-05-06T15:59:28Z")

</div>

Just wanted to chime in here that we found a (maybe not optimal) solution for this issue. We also had a global `@GenericGenerator` that we needed to replace after migrating. We also did not want to move this to every Entity. Hibernate Sequence generator actually does what we wanted, but has a default increment size of 50, and we had 1 before. Since we also did not want to migrate every sequence to use this increment size (yet), we needed another solution. What seems to work fine is to actually just do what the migration steps for `@GenericGenerator` suggest.

```auto
@IdGeneratorType(CustomSequenceGenerator.class)
@Retention(RUNTIME)
@Target({METHOD, FIELD})
public @interface OptimizedSequence {
    int incrementBy() default 1;
}

```

And:

```auto
public class CustomSequenceGenerator extends SequenceStyleGenerator implements BeforeExecutionGenerator {

    private final int incrementSize;

    public CustomSequenceGenerator(OptimizedSequence config) {
        this.incrementSize = config.incrementBy();
    }

    @Override
    protected int determineIncrementSize(Properties params) {
        return incrementSize;
    }
}

```

This just extends the `SequenceStyleGenerator` of Hibernate and overwrites the `determineIncrementSize` function to provide another default.

So far this is working fine and we did not encounter issues, but i am not sure how stable this will be for upgrades in the future.
