@GeneratedValue(strategy =“IDENTITY”)vs. @GeneratedValue(strategy =“SEQUENCE”) [英] @GeneratedValue(strategy="IDENTITY") vs. @GeneratedValue(strategy="SEQUENCE")

查看:112
本文介绍了@GeneratedValue(strategy =“IDENTITY”)vs. @GeneratedValue(strategy =“SEQUENCE”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是hibernate的新手。我不明白以下两种主键生成策略:

I'm new to hibernate. I do not understand the the following two primary key generation strategies:


  1. 身份

  2. li>
  1. Identity
  2. Sequence

可以请某人解释这两个工作是如何进行的,以及这两者之间有什么区别?

Can someone please explain how these two work and what is the difference between these two?

推荐答案

引用 Java Persistence / Identity and Sequencing

Quoting Java Persistence/Identity and Sequencing:


身份验证排序在数据库中使用特殊IDENTITY列数据库在插入行时自动为对象分配一个id。许多数据库都支持标识列,例如 MySQL,DB2,SQL Server,Sybase和Postgres 。 Oracle不支持IDENTITY列,但它们可以通过使用序列对象和触发器来模拟。

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 Postgres. Oracle does not support IDENTITY columns but they can be simulated through using sequence objects and triggers.

简单英语:您最多只标记一个 ID 列作为IDENTITY。数据库引擎会自动为您提供下一个可用的值。

In plain English: you mark at most one ID column in your table as IDENTITY. The database engine will put next available value for you automatically.

和:

And:


序列对象使用特殊数据库对象生成id。序列对象仅在某些数据库中受支持,如 Oracle,DB2和Postgres 。通常,SEQUENCE对象具有名称,INCREMENT和其他数据库对象设置。每次选择< sequence> .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 <sequence>.NEXTVAL is selected the sequence is incremented by the INCREMENT.

序列更灵活,更复杂一些。您可以在数据库中定义一个额外的对象,并在称为 sequences 的表,触发器等之后。序列基本上是命名计数器,你可以在查询中的任何地方使用。

Sequences are more flexible and slightly more complex. You define an extra object in your database next to tables, triggers, etc. called sequences. Sequences are basically named counter you can use anywhere inside queries.

这篇关于@GeneratedValue(strategy =“IDENTITY”)vs. @GeneratedValue(strategy =“SEQUENCE”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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