Gerd Aschemann
Gerd Aschemann

Reputation: 504

org.hibernate.MappingException: The increment size of the sequence is set to [10] in the entity mapping while ... size is [1]

We run into a problem when updating to Spring Boot 2.2 and the associated Hibernate 5.4.x.

We do have the following sequence generator

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hilo_sequence_generator")
@GenericGenerator(
        name = "hilo_sequence_generator",
        strategy = "...",
        parameters = {
                @Parameter(name = "sequence_name", value = "XXX_SEQUENCE"),
                @Parameter(name = "initial_value", value = "1"),
                @Parameter(name = "increment_size", value = "10"),
                @Parameter(name = "optimizer", value = "hilo")
        })
private Long id;

With the update to SB 2.2 / HB 5.4 we get the following initialization error

org.hibernate.MappingException: The increment size of the sequence is set to [10] in the entity mapping while the associated database sequence increment size is [1]

The DB sequence increment size is 1:

                    Sequence "...xxx_sequence"
  Type  | Start | Minimum |       Maximum       | Increment | Cycles? | Cache
--------+-------+---------+---------------------+-----------+---------+-------
 bigint |     1 |       1 | 9223372036854775807 |         1 | no      |     1

However, to my understanding the (soft) increment size of the hilo algorithm has nothing to do with the (hard) increment size of the DB.

Is this an error in HB or can we circumvent the problem somehow?

WRT to the questions of Jens:

Upvotes: 10

Views: 9360

Answers (3)

tom
tom

Reputation: 1493

In my case, I was working on migrating a legacy application that was still using hbm.xml files. I added the following to the <id/> section and it fixed it.

<param name="increment_size">1</param>

It looks something like this:

<id name="tableId" type="java.lang.Long" column="TABLE_ID">
    <generator class="sequence">
        <param name="sequence">TABLE_ID_SEQ</param>
        <param name="increment_size">1</param>
    </generator>
</id>

Upvotes: 1

Sachithra Pathiraja
Sachithra Pathiraja

Reputation: 149

I think if you change @Parameter(name = "increment_size", value = "10") to @Parameter(name = "increment_size", value = "1") this will work. why do you want to set the value as 10?

Upvotes: 1

Jose Mena
Jose Mena

Reputation: 91

I experienced the same issue, you can fix it with the following annotation in the id field:

@SequenceGenerator(name = "hilo_sequence_generator", allocationSize = 1)

Upvotes: 1

Related Questions