H2Dialect @GeneratedValue regression on schema generation, uses sequence instead of generated by default as identity

Description

In Hibernate 4.x, specifically 4.3.11, all worked as expected.

persistence.xml snippet

4.x generated SQL

In 5.x the DB structure has changed in incompatible ways.

5.x generated SQL

I have confirmed the dialect values are sensible. The error seems to be inside / around the SessionFactoryImpl's identifierGenerators. While the dialect indicates Identity generation, the generator seems to be a result of DefaultIdentifierGeneratorFactory, which produces sequence based ids.

Specifically the metadata.getEntityBindings() returns a PersistentClass model where the identifier is a SimpleValue whose identifierGenerator is a SequenceStyleGenerator.

This can be backtracked to:

EntityManagerFactoryBuilderImpl

This is not related to:

Environment

Java 7, Java 8, h2-1.4.200.jar

Activity

Show:
IT Support
April 7, 2020, 9:15 PM

This may be a change in “design” ut not easily identified in the change logs - quoting https://docs.jboss.org/hibernate/orm/5.0/userguide/html_single/Hibernate_User_Guide.html#identifiers-generators :

The discussions below assume that the application is using Hibernate’s "new generator mappings" as indicated by the hibernate.id.new_generator_mappings setting or MetadataBuilder.enableNewIdentifierGeneratorSupport method during bootstrap. Starting with Hibernate 5, this is set to true by default. If applications set this to false the resolutions discussed here will be very different. The rest of the discussion here assumes this setting is enabled (true).

 

Sanne Grinovero
April 8, 2020, 1:43 PM

I’ll close this based on suggestion from the mailing list:

Thanks!

Assignee

IT Support

Reporter

IT Support

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure