Hibernate 6 migration: Using different ID generation strategy for a specific database type (SQL Server)

We are currently migrating a large framework from Hibernate 5 to the newest Hibernate 6 version. Part of our framework is the support of various relational databases, e.g. PostgreSQL, MS SQL Server and Oracle.

With Hibernate 6, there have been major changes to the automatic generation of IDs. On the code side, the IDs of our entities are generated with GenerationStrategy.AUTO. For Postgres, this previously meant that IDs were generated from a single sequence (hibernate_sequence). In SQL Server, we have generated the IDs via auto-increment on the ID column for backward compatibility reasons (using the configuration property “hibernate.id.new_generator_mappings=LegacyFallbackInterpreter”).

Is there a way in Hibernate 6 to override the ID generation strategy for individual database systems (in this case for MS SQL Server)? We would like to continue using auto-increment on the ID column for SQL Server and a single sequence for Postgres (using the new configuration property “hibernate.id.db_structure_naming_strategy=single”.

Thanks in advance for your help :slight_smile:

See HHH-18620 which adds first class support for this pattern in ORM 7.0 through the @NativeGenerator annotation.

As far as I understand the hibernate.id.new_generator_mappings setting, it is a boolean, so you’d have to set it to false to make it work the way you’re intending.

Thanks for your reply. That sounds promising! We will check this out using the v7 beta version.

Yea, you are absolutely right. hibernate.id.new_generator_mappings expects a boolean value, we used it wrong all the time, but because of an implementation detail inside the StandardConverters our wrong value led to the wanted result - Boolean.parseBoolean(“LegacyFallbackInterpreter”) returns false. How fortunate :smiley:

hibernate.id.new_generator_mappings has been removed in Hibernate 6 as far as i can see, right?

It was removed in Hibernate ORM 7, since it got the replacement through the @NativeGenerator annotation.