GeneratedValue 策略之间的差异 [英] The differences between GeneratedValue strategies

查看:15
本文介绍了GeneratedValue 策略之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Doctrine docs中,他们提到存在@GeneratedValue 注释的几种不同策略:

In the Doctrine docs they mention that there exists a few different strategies for the @GeneratedValue annotation:

  • AUTO
  • 序列
  • TABLE
  • 身份
  • UUID
  • 自定义
  • NONE

有人能解释一下所有这些策略之间的区别吗?

Would someone please explain the differences between all thees strategies?

推荐答案

检查 最新的教义文档

总结如下:可能的生成策略列表:

Here is a summary : the list of possible generation strategies:

AUTO(默认):告诉 Doctrine 选择所用数据库平台首选的策略.MySQL、SQLite 和 MsSQL 的首选策略是 IDENTITY,Oracle 和 PostgreSQL 的首选策略是 SEQUENCE.这种策略提供了完全的可移植性.

AUTO (default): Tells Doctrine to pick the strategy that is preferred by the used database platform. The preferred strategies are IDENTITY for MySQL, SQLite and MsSQL and SEQUENCE for Oracle and PostgreSQL. This strategy provides full portability.

SEQUENCE: 告诉 Doctrine 使用数据库序列来生成 ID.此策略目前不提供完全的可移植性.Oracle、PostgreSql 和 SQL Anywhere 都支持序列.

SEQUENCE: Tells Doctrine to use a database sequence for ID generation. This strategy does currently not provide full portability. Sequences are supported by Oracle and PostgreSql and SQL Anywhere.

IDENTITY: 告诉 Doctrine 使用数据库中的特殊标识列,这些列在插入行时生成一个值.此策略目前不提供完全的可移植性,并受以下平台支持:

IDENTITY: Tells Doctrine to use special identity columns in the database that generate a value on insertion of a row. This strategy does currently not provide full portability and is supported by the following platforms:

  • MySQL/SQLite/SQL Anywhere =>AUTO_INCREMENT
  • MSSQL =>身份
  • PostgreSQL =>SERIAL

TABLE: 告诉 Doctrine 使用单独的表来生成 ID.这种策略提供了完全的可移植性.此策略尚未实施!

TABLE: Tells Doctrine to use a separate table for ID generation. This strategy provides full portability. This strategy is not yet implemented!

NONE: 告诉 Doctrine 标识符是由您的代码分配并因此生成的.必须在将新实体传递给 EntityManager#persist 之前进行分配.NONE 与完全删除 @GeneratedValue 相同.

NONE: Tells Doctrine that the identifiers are assigned, and thus generated, by your code. The assignment must take place before a new entity is passed to EntityManager#persist. NONE is the same as leaving off the @GeneratedValue entirely.

UUID: 告诉 Doctrine 使用内置的通用唯一标识符生成器.这种策略提供了完全的可移植性.

UUID: Tells Doctrine to use the built-in Universally Unique Identifier generator. This strategy provides full portability.

这篇关于GeneratedValue 策略之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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