Why is the default Hibernate generator for PostgreSql "SequenceGenerator" and not "IdentityGenerator"?

The default identifier generator for Postgresql in Hibernate is SequenceGenerator [1]. that is, Hibernate will perform a SELECT nextval('hibernate_sequence') to generate an identifier before executing INSERT foo (id, ...) VALUES (123, ...) when committing the session.

However, PostgreSql supports columns of auto-increment identifiers (see, for example, [2]), and the default generator for all other databases that support auto-increment use this function [3], as well as insert without an id value and query databases for new identifier (before the session commit, but in the session transaction).

I saw a recent discussion [4] suggesting that the former strategy be better overall because of insert-to-session mismatch.

If SequenceGenerator is better (according to [4]), why is this not the default for databases that support it (see [3])?

If IdentityGenerator is better, why does PostgreSql explicitly select a SequenceGenerator when Postgres supports the first (according to [2])?

I tried to find the history of the solution to override the default value in the Postgres dialect (see [1]), but I could not find the appropriate commit on GitHub. I returned the code back to the SVN repository, but the trace caught a cold when the PostgreSQLDialect file was added to r11563 with a useless message saying "maven migration" was committed [5]. It seems I can no longer follow the story. Can someone find the commit that added this override? Perhaps there is more information in the commit message.

Thanks in advance.

[1] https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java#L267

[2] PostgreSQL autorun

[3] https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java#L639

[4] http://nhforge.org/blogs/nhibernate/archive/2009/03/20/nhibernate-poid-generators-revealed.aspx

[5] https://source.jboss.org/browse/Hibernate/core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java?focusedRev=14993&fromRev=11563&toRev=14993#r14993

+7
source share
2 answers

Perhaps because afterInsert generators are usually split into PGs in NHibernate, because it uses the outSource style OracleStyle, which is not supported by the npgsql-ADONET driver, which returns the result as a query result, not a parameter.

SQL: INSERT INTO .... return id in nhoutparameter ;: nhoutparameter = null;

using Oracle, it works

 command.Execute(); object id = command.Parameter["nhoutparameter"].Value; Assert.NotNull(id); 

in PG not. It should be

 object id = command.ExecuteScalar(); 
+2
source

This is just an assumption, since I cannot find good documents with functions / versions in postgres, but ...

Perhaps the postgres dialect was added before the serial interface was implemented, stable, widely used, or the developers who implemented the dialect knew about it. Changing the default identifier generator for a dialect will be a change, and this is bad.

0
source

All Articles