为“GenerationType.AUTO”实际选择了什么策略为主要数据库? [英] What strategy is actually selected for "GenerationType.AUTO" for the major databases?

查看:1600
本文介绍了为“GenerationType.AUTO”实际选择了什么策略为主要数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hibernate文档(5.1.2.2。标识符生成器)状态


AUTO:选择IDENTITY,SEQUENCE或TABLE底层数据库。

AUTO: selects IDENTITY, SEQUENCE or TABLE depending upon the capabilities of the underlying database.

但我无法找到文档/概述@GeneratedValue策略用于定义特定数据库作为GenerationType.AUTO。

But I'm unable to find a documentation/overview what @GeneratedValue strategy is used for the specific databases when defining them as GenerationType.AUTO.

有人知道是否有人维护主要数据库(例如Oracle,DB2,PostgreSQL,MySQL,MSSQL)的实际生成策略的列表。 ..)?

Does anybody know whether someone maintains a list of the actual generation strategy for the major databases (e.g. Oracle, DB2, PostgreSQL, MySQL, MSSQL, ...)? And where to find it?

推荐答案

此链接关于Java Persistence API,并且定期更新。
http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing

This link is about Java Persistence API and seems regularly updated. http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing


身分序列



身份序列在数据库中使用特殊的IDENTITY列b $ b允许数据库在插入
行时自动为对象分配一个id。在许多数据库
(如 MySQL,DB2,SQL Server,Sybase和PostgreSQL )中支持标识列。 Oracle不支持
不支持IDENTITY列,但可以使用序列对象和触发器来模拟

Identity sequencing

Identity sequencing uses special IDENTITY columns in the database to allow the database to automatically assign an id to the object when its row is inserted. Identity columns are supported in many databases, such as MySQL, DB2, SQL Server, Sybase, and PostgreSQL. Oracle does not support IDENTITY columns but its is possible to simulate them using sequence objects and triggers.

序列对象使用特殊的数据库对象来生成id。
仅在某些数据库中支持序列对象,例如 Oracle,
DB2和Postgres
。通常,SEQUENCE对象具有名称,
INCREMENT和其他数据库对象设置。每次选择
.NEXTVAL时,序列都会被
INCREMENT增加。

Sequence objects use special database objects to generate ids. Sequence objects are only supported in some databases, such as Oracle, DB2, and Postgres. Usually, a SEQUENCE object has a name, an INCREMENT, and other database object settings. Each time the .NEXTVAL is selected the sequence is incremented by the INCREMENT.

如果数据库(如DB2)支持IDENTITY列,而序列hibernate选择Identity列,请参阅方言

If the database such as DB2 supports both IDENTITY columns and Sequences hibernate chooses Identity columns, see Dialect:

public Class getNativeIdentifierGeneratorClass() {
    if ( supportsIdentityColumns() ) {
        return IdentityGenerator.class;
    }
    else if ( supportsSequences() ) {
        return SequenceGenerator.class;
    }
    else {
        return TableHiLoGenerator.class;
    }
}

您可以检查supportsIdentityColumns通过查看 org.hibernate.dialect 包。

You can check what is returned from supportsIdentityColumns() and supportsSequences() for each database by looking at the relevant dialect in the org.hibernate.dialect package.

这篇关于为“GenerationType.AUTO”实际选择了什么策略为主要数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆