gpt4 book ai didi

database - 各大数据库 "GenerationType.AUTO"究竟选择了什么策略?

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:55 25 4
gpt4 key购买 nike

Hibernate documentations (5.1.2.2. Identifier generator)

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

但是我无法找到文档/概述在将特定数据库定义为 GenerationType.AUTO 时使用什么 @GeneratedValue 策略。

有人知道是否有人维护了一份主要数据库(例如 Oracle、DB2、PostgreSQL、MySQL、MSSQL 等)的实际生成策略列表吗?在哪里可以找到它?

最佳答案

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

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.

Sequence objects

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 列并且 Sequences hibernate 选择 Identity 列,请参阅 Dialect :

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

您可以通过查看 org.hibernate.dialect 中的相关方言来检查每个数据库的 supportsIdentityColumns() 和 supportsSequences() 返回的内容。包。

关于database - 各大数据库 "GenerationType.AUTO"究竟选择了什么策略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19875993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com