简体   繁体   English

Hibernate自动值生成策略之间的区别?

[英]Difference between Hibernate Automatic value generation strategies?

What is the difference between these two Automatic value generation strategies? 这两种自动价值生成策略有什么区别?

 1. @GeneratedValue
 2. @GeneratedValue(strategy=IDENTITY)

This is like following: 如下所示:

AUTO Indicates that the persistence provider should pick an appropriate strategy for the particular database. AUTO指示持久性提供程序应为特定数据库选择适当的策略。

IDENTITY Indicates that the persistence provider must assign primary keys for the entity using database identity column. IDENTITY指示持久性提供程序必须使用数据库标识列为实体分配主键。

SEQUENCE Indicates that the persistence provider must assign primary keys for the entity using database sequence column. SEQUENCE指示持久性提供程序必须使用数据库序列列为实体分配主键。

TABLE Indicates that the persistence provider must assign primary keys for the entity using an underlying database table to ensure uniqueness. TABLE表示持久性提供程序必须使用基础数据库表为实体分配主键,以确保唯一性。

Refer to the API here http://docs.oracle.com/javaee/5/api/javax/persistence/GenerationType.html 在此处参考API http://docs.oracle.com/javaee/5/api/javax/persistence/GenerationType.html

If you don't set the strategy attribute, it defaults to AUTO . 如果未设置strategy属性,则默认为AUTO From the Hibernate docs: 从Hibernate文档中:
AUTO: selects IDENTITY, SEQUENCE or TABLE depending upon the capabilities of the underlying database. AUTO:根据基础数据库的功能选择IDENTITY,SEQUENCE或TABLE。

The difference is that @GeneratedValue uses AUTO strategy as default while @GeneratedValue(strategy=IDENTITY) uses IDENTITY strategy 区别在于@GeneratedValue使用AUTO策略作为默认策略,而@GeneratedValue(strategy = IDENTITY)使用IDENTITY策略

Here are the different options for strategy 这是策略的不同选择

AUTO - Indicates that the persistence provider should pick an appropriate strategy for the particular database. AUTO-指示持久性提供程序应为特定数据库选择适当的策略。

IDENTITY - Indicates that the persistence provider must assign primary keys for the entity using database identity column. IDENTITY-表示持久性提供程序必须使用数据库标识列为实体分配主键。

SEQUENCE - Indicates that the persistence provider must assign primary keys for the entity using database sequence column. SEQUENCE-指示持久性提供程序必须使用数据库序列列为实体分配主键。

TABLE - Indicates that the persistence provider must assign primary keys for the entity using an underlying database table to ensure uniqueness. TABLE-表示持久性提供程序必须使用基础数据库表为实体分配主键,以确保唯一性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM