Uploaded image for project: 'Hibernate ORM'
  1. HHH-11011

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


    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 5.0.9, 5.2.1
    • Fix Version/s: None
    • Component/s: hibernate-core
    • Labels:
    • Environment:
      PostgreSQL 9.4
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
    • Sprint:


      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:

      @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,




            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: