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

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

问题描述

教义文档中,他们提到存在 @GeneratedValue 注释的一些不同策略:




  • AUTO

  • SEQUENCE

  • TABLE

  • IDENTITY

  • UUID

  • CUSTOM

  • NONE



有人可以解释所有的策略之间的差异吗?

解决方案

检查最新的教义文档



这里是一个总结:
可能的生成策略列表: / p>

自动(默认):告诉学说选择策略使用数据库平台优先的egy。对于Oracle和PostgreSQL,首选策略是MySQL,SQLite和MsSQL的 IDENTITY SEQUENCE 。这个策略提供了完整的可移植性。



SEQUENCE:告诉Doctrine使用数据库序列 ID 一代。这个策略目前没有提供完整的可移植性。序列由Oracle和PostgreSql支持。



IDENTITY:告诉原则在数据库中使用特殊标识列,行。此策略目前无法提供完整的可移植性,并受以下平台的支持:




  • MySQL / SQLite => AUTO_INCREMENT

  • MSSQL => IDENTITY

  • PostgreSQL => SERIAL



表:告诉学说使用单独的表格 ID 生成。这一策略提供了完整的可移植性。



NONE:告知原则,标识符被分配,从而生成,通过你的代码必须在新实体传递给EntityManager#persist之前进行分配。 NONE 与完全退出 @GeneratedValue 相同。



从版本2.3:



UUID:告诉学说使用内置的通用唯一标识符生成器。此策略提供完整的可移植性。


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

  • AUTO
  • SEQUENCE
  • TABLE
  • IDENTITY
  • UUID
  • CUSTOM
  • NONE

Would someone please explain the differences between all thees strategies?

解决方案

Check the latest doctrine documentation

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

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: 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.

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 => AUTO_INCREMENT
  • MSSQL => IDENTITY
  • PostgreSQL => SERIAL

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

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.

SINCE VERSION 2.3 :

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

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

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