JPA通用策略生成器(@GeneratedValue 四种标准用法为TABLE, SEQUENCE, IDENTITY, AUTO)

简介: JPA通用策略生成器(@GeneratedValue 四种标准用法为TABLE, SEQUENCE, IDENTITY, AUTO)

JPA通用策略生成器

查看JPA的源码可知:

packagejavax.persistence;
/** * Defines the types of primary key generation strategies. ** @see GeneratedValue** @since Java Persistence 1.0*/publicenumGenerationType { 
/*** Indicates that the persistence provider must assign * primary keys for the entity using an underlying * database table to ensure uniqueness.*/TABLE, 
/*** Indicates that the persistence provider must assign * primary keys for the entity using a database sequence.*/SEQUENCE, 
/*** Indicates that the persistence provider must assign * primary keys for the entity using a database identity column.*/IDENTITY, 
/*** Indicates that the persistence provider should pick an * appropriate strategy for the particular database. The * <code>AUTO</code> generation strategy may expect a database * resource to exist, or it may attempt to create one. A vendor * may provide documentation on how to create such resources * in the event that it does not support schema generation * or cannot create the schema resource at runtime.*/AUTO}

JPA提供的四种标准用法为TABLE, SEQUENCE, IDENTITY, AUTO

TABLE:使用一个特定的数据库表格来保存主键。  

SEQUENCE:根据底层数据库的序列来生成主键,条件是数据库支持序列。  

IDENTITY:主键由数据库自动生成(主要是自动增长型) 。

AUTO:主键由程序控制。  

 

详情请查看另外一篇,感觉写的很全,如有兴趣的话,可以看看:https://blog.csdn.net/tree_java/article/details/71158122


本文首发于CSDN,为博主原创文章,如果需要转载,请注明出处,谢谢!


完结!

相关文章
|
算法 Java Spring
自定义全局自增ID生成器(上)
自定义全局自增ID生成器
179 0
|
NoSQL Redis
自定义全局自增ID生成器(下)
自定义全局自增ID生成器
205 0
|
SQL 关系型数据库 索引
开发指南—Sequence—隐式用法—查看表信息及相关Sequence类型
本文主要介绍如何对使用Sequence类型作为自增列的表信息以及相关Sequence类型进行查看。
|
索引
开发指南—Sequence—隐式用法—CREATE TABLE
在为拆分表或广播表的主键定义AUTO_INCREMENT后,Sequence可以用于自动填充主键,由PolarDB-X自动维护。 扩展标准建表语法,增加了自增列的Sequence类型,如果未指定类型关键字,则默认类型为GROUP。PolarDB-X自动创建的、跟表相关联的Sequence名称,都是以AUTO_SEQ_为前缀,后面加上表名。
开发指南—DAL语句—SET—SET语句变量设置
您可以通过SET语句设置各类变量,包括用户自定义的变量、session变量和global变量。
《Drools7.0.0.Final规则引擎教程》番外实例篇——activation-group的多FACT对象
《Drools7.0.0.Final规则引擎教程》番外实例篇——activation-group的多FACT对象
252 0