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

While upgrading from hibernate 3 to hibernate 5, this was one of the issues.

Here is how id fields were defined in hibernate 3.

@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="my_seq_gen")
@SequenceGenerator(name="my_seq_gen", sequenceName="MY_SEQ")
private long id;

So now, I added allocationSize = 1 to resolve the issue

@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="my_seq_gen")
@SequenceGenerator(name="my_seq_gen", sequenceName="MY_SEQ", allocationSize = 1)
private long id;

And for new Ids I used the below declaration

@GenericGenerator(
name = "MySequenceGenerator",
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
parameters = {
@Parameter(name = "sequence_name", value = "MySequence"),
@Parameter(name = "initial_value", value = "1"),
@Parameter(name = "increment_size", value = "1")
}
)
@GeneratedValue(generator = "MySequenceGenerator")
@Id
private Long id = null;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.