ORM >= 5.0.9 not picking up sequence name when hibernate.id.new_generator_mappings = false

Description

Hi everybody,

In an application (http://euregjug.eu, also on Github), i have the requirements to run on H2 and on Postgres.

Tables are generated with "serial" primary key columns, that is auto incrementing primary keys.

In Hibernate 4.3 I could use the following ID column mappings:

@Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.AUTO, generator = "links_id_seq_generator") @SequenceGenerator(name = "links_id_seq_generator", sequenceName = "links_id_seq")

On H2, it picked up Identity, on Postgres it chose Sequence, using the given sequence which is automatically created by Postgres when used something like

create table links ( id serial primary key );

After upgrading to Hibernate 5.0.9 and setting "hibernate.id.new_generator_mappings" to false, Hibernate does seem to lookup the generator but doesn't pick up the sequence, instead tries to use hibernate_sequence.

It picks up the correct sequence when using the new_generator_mappings, but then i have to configure "allocationSize = 1, initialValue = 1" or even worse, have to resort to GenericGenerator for configuring which optimization to use.

What does work for both databases is using Identiy (which basically is what i want anyway for both H2 and Postgres, see https://github.com/EuregJUG-Maas-Rhine/site/commit/7070dcebd432a338e14efb82b2d8abbae00b4b18), but Hibernate not picking up the sequence is an annoyance, especially due to the fact of recently released Spring Boot 1.4, which sets the new_generator_mappings to false by default.

Attached are two test cases, one for 4 and one for 5, running agains Postgres.

4 works as expected, 5 not. For 5 I'd expect hibernate to pick up the "links_id_seq" and fail then on the insert as the sequence is not correctly configured for use with the new, optimized sequence generator.

The "Link" example is from my JUGs site.

Thanks for looking at this,
Michael

Attachments

2
  • 31 Jul 2016, 10:34 AM
  • 31 Jul 2016, 10:34 AM

Activity

Show:

Vlad Mihalcea August 1, 2016 at 5:32 AM

This is a duplicate of HHH-10876. , I think we should backport https://hibernate.atlassian.net/browse/HHH-10876#icft=HHH-10876 to 5.1 and 5.0 because it causes trouble as described in this issue.

Duplicate

Details

Assignee

Reporter

Components

Affects versions

Priority

Created July 31, 2016 at 10:34 AM
Updated December 3, 2024 at 9:29 AM
Resolved August 1, 2016 at 5:32 AM